import java.util.*;
public class 加减乘数 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a;
String d;
float b, c;
System.out.println("+加法运算 -减法运算");
System.out.println("* 乘法运算 /除法运算");
System.out.println("请选择数字1~4:");
a = in.nextInt();
switch (a) {
case 1:
System.out.println("请输入一个整数:");
b = in.nextFloat();
System.out.println("请输入另一个整数:");
c = in.nextFloat();
System.out.println(b + "+" + c + "=" + (b + c));
break;
case 2:
System.out.println("请输入一个整数:");
b = in.nextFloat();
System.out.println("请输入另一个整数:");
c = in.nextFloat();
System.out.println(b + "-" + c + "=" + (b - c));
break;
case 3:
System.out.println("请输入一个整数:");
b = in.nextFloat();
System.out.println("请输入另一个整数:");
c = in.nextFloat();
System.out.println(b + "*" + c + "=" + (b * c));
break;
case 4:
System.out.println("请输入一个整数:");
b = in.nextFloat();
System.out.println("请输入另一个整数:");
c = in.nextFloat();
if (c != 0) {
System.out.println(b + "/" + c + "=" + (b / c));
} else
System.out.println("error!");
break;
default:
System.out.println("error!");
}
}
}
|
|