/*function:
*使用switch语句改写下列if语句:
* int a = 3;
* int x = 100;
* if(a==1)
* x+=5;
*else if(a==2)
* x+=10;
*else if(a==3)
* x+=16;
*else if(a==4)
* x+=34;
* else
* x += 100;
*code by:ICE_Watermelon
*date:2015.11.25
*/
public class SwitchChange{
public static void main(String [] args){
int a = 3;
int x = 100;
switch(a){
case 1:
x += 5;
break;
case 2:
x += 10;
break;
case 3:
x += 16;
break;
case 4:
x += 34;
break;
default:
x += 100;
break;
}
System.out.println("x = " + x);
}
}
*使用switch语句改写下列if语句:
* int a = 3;
* int x = 100;
* if(a==1)
* x+=5;
*else if(a==2)
* x+=10;
*else if(a==3)
* x+=16;
*else if(a==4)
* x+=34;
* else
* x += 100;
*code by:ICE_Watermelon
*date:2015.11.25
*/
public class SwitchChange{
public static void main(String [] args){
int a = 3;
int x = 100;
switch(a){
case 1:
x += 5;
break;
case 2:
x += 10;
break;
case 3:
x += 16;
break;
case 4:
x += 34;
break;
default:
x += 100;
break;
}
System.out.println("x = " + x);
}
}