Scanner input = new Scanner(System.in);
System.out.println("please choose the operator");
System.out.println("1-->+ \n2-->- \n3-->* \n4-->/");
int z = input.nextInt();
switch (z) {
case 1:
System.out.println("your result is" + (x + y));
break;
case 2:
System.out.println("your result is" + (x - y));
break;
case 3:
System.out.println("your result is" + (x * y));
break;
case 4:
System.out.println("your result is" + (x/y));
break;
default:
System.out.println("choose the option from listed above");
break;
}
上面的代碼轉換功能是在開關計算器... 查詢: 我如何能在默認的情況下再次調用切換功能?查詢有關使用Java
開關是一個陳述,而不是一個功能。在Java中稱爲函數的方法稱爲方法。如果你想重複,你需要在while循環中包含所有的代碼。 –
你是否設法使它工作? – luizfzs