網易第三季度營收 222 億元同比增長 19%,網路遊戲毛利率 64.5%
阿新 • • 發佈:2021-11-16
-
-
利用迴圈+switch進行使用者互動
-
傳遞需要操作的兩個數
-
輸出結果
public class Demo05 {
public static void main(String[] args) {
while (true) {
Scanner scanner = new Scanner(System.in);
System.out.println("請輸入第一個數字:");
int a = scanner.nextInt();
System.out.println("要進行的運算是:");
String s = scanner.next();
System.out.println("請輸入第二數");
int b = scanner.nextInt();
// scanner.close();
switch (s) {
case "+":
System.out.println("結果是:" + add(a, b));
break;
case "-":
System.out.println("結果是:" + reduce(a, b));
break;
case "*":
System.out.println("結果是:" + mul(a, b));
break;
case "/":
System.out.println("結果是:" + div(a, b));
break;
}
}
}
public static int add(int a,int b){
return a+b;
}
public static int reduce(int a,int b){
return a-b;
}
public static int mul(int a,int b){
return a*b;
}
public static int div(int a,int b){
return a/b;
}
}