刚才制作了一个简易计算器,把if语句改成switch语句,合理吗??
import java.util.*;class C{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("-----------------------");
System.out.println("您好,您已经进入计算器:");
System.out.println("-----------------------");
System.out.println("请您输入第一个数:");
int A = in.nextInt();
System.out.println("请您输入符号:(1:+,2:-,3:*,4:/)");
int B = in.nextInt();
System.out.println("请输入下一个数:");
int C =in.nextInt();
System.out.println("您的计算结果是:");
/*if(B==1){
System.out.println("="+(A+C));
}
if(B==2){
System.out.println("="+(A-C));
}
if(B==3){
System.out.println("="+(A*C));
}
if(B==4){
System.out.println("="+(A/C)) ;
}
}*/
String D ="标记";
switch (B){
case 1:
D = "+";
System.out.println("="+(A+C));
break;
case 2:
D = "-";
System.out.println("="+(A-C));
break;
case 3:
D = "*";
System.out.println("="+(A*C));
break;
case 4:
D = "/";
System.out.println("="+(A/C));
break;
}
}
}