我的程序接受用户的输入,第一个数字,操作(+ - * / ^)然后是第二个数字。当我输入 5 / 0 时,它显示错误!!!不能除以 0 。这就是它应该做的。但是,当我输入 5 / 5(即 1)时,我会收到错误消息。
do {
try {
if (opperation == "/" && num2 == 0);
throw new ArithmeticException();
} catch (ArithmeticException ae) {
System.out.println("ERROR !!! Cannot divide by 0");
}
System.out.println("Enter First Number");
num1 = scan.nextInt();
System.out.println("ENTER Opperation: ");
opperation = scan.next();
System.out.println("ENTER Second Number: ");
num2 = scan.nextInt();
} while (num2 == 0);