HomeWork01_4个方法:加减乘除
public class Test01 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < 4; i++) {
System.out.print("请输入第一个数字:");
int sc1 = scanner.nextInt();
System.out.print("请输入第二个数字:");
int sc2 = scanner.nextInt();
System.out.print("请输入加,减,乘,除:");
String sc3 = scanner.next();
switch (sc3) {
case ("加"):
System.out.println(add(sc1, sc2));
break;
case ("减"):
System.out.println(del(sc1, sc2));
break;
case ("乘"):
System.out.println(cheng(sc1, sc2));
break;
case ("除"):
System.out.println(mod(sc1, sc2));
break;
}
}
scanner.close();
}
public static int add(int a, int b) {
int result = a + b;
return result;
}
public static int del(int a, int b) {
int result = a - b;
return result;
}
public static int cheng(int a, int b) {
int result = a * b;
return result;
}
public static int mod(int a, int b) {
int result = a / b;
return result;
}
}