import java.io.PrintStream;
import java.util.Scanner;
public class BasicCalculator
{
public static void main(String[] args)
{
int ADDITION = 1;
int SUBTRACTION = 2;
int MULTIPLICATION = 3;
int DIVISION = 4;
int EXIT = 5;
Scanner keyboard = new Scanner(System.in);
int choice;
do
{
System.out.println("Choose from the following:");
System.out.println("1. Add 2 integers");
System.out.println("2. Subtract 2 integers");
System.out.println("3. Multiply 2 integers");
System.out.println("4. Divide 2 integers");
System.out.println("5. Exit");
System.out.print("Enter choice: ");
choice = keyboard.nextInt();
if ((choice == 1) || (choice == 2) || (choice == 3) || (choice == 4))
{
System.out.print("Enter first integer: ");
int left = keyboard.nextInt();
System.out.print("Enter second integer: ");
int right = keyboard.nextInt();
switch (choice)
{
double Result;
case 1:
Result = left + right;
System.out.println(left + " + " + right + " = " + Result);
break;
case 2:
Result = left - right;
System.out.println(left + " - " + right + " = " + Result);
break;
case 3:
Result = left * right;
System.out.println(left + " * " + right + " = " + Result);
break;
case 4:
Result = left/right;
System.out.println(left + "/" + right + " = " + Result);
}
System.out.println();
}
} while (choice != 5);
}
}
錯誤:簡單的語法錯誤
BasicCalculator.java:34: error: case, default, or '}' expected
int Result;
^
BasicCalculator.java:34: error: case, default, or '}' expected
int Result;
^
BasicCalculator.java:34: error: case, default, or '}' expected
int Result;
上面的代碼是我爲我的介紹對計算機編程類項目,我碰到的是從格式問題而產生了一些錯誤。我可以得到一些基本的幫助什麼導致錯誤。我仍然試圖習慣於閱讀記事本++中的錯誤描述並理解它們的含義。
第34行是什麼行? – Mureinik
您不能在switch-statement中聲明變量。 –