舉個我想要使用此代碼闡述的想法是這樣的:在陣列節省運營商,錯誤
- 輸入兩個數字:10 7
- 選擇運營商:如(+, - ,*和/)
- 什麼是10 * 7?
正確!
int[] arr = new int[5]; System.out.println("enter two numbers: "); arr[1] = sc.nextInt(); arr[2] = sc.nextInt(); System.out.println("Choose Operator: "); arr[3] = sc.nextInt(); int operator = arr[1]+arr[3]+arr[2]; System.out.print("what's "+operator); int svar = sc.nextInt(); if (svar == operator) System.out.println("Correct!"); else System.out.println("Wrong - the right answer is "+operator);
現在我有這個代碼中運行的一些方面的問題。它工作正常,編譯但每次程序要求爲「選擇運營商」具有以下錯誤編譯迴應:
- 異常線程「main」
- java.util.InputMismatchException在在
- java.util.Scanner.next
- java.util.Scanner.throwFor(未知
- 源)(未知
- 源)在
- java.util.Scanner.nextInt(未知
- 源)在
- java.util.Scanner.nextInt(未知
- 源)
- 在test1.main(TEST1。 Java的:13)
我知道我該怎麼去處理這一個。但目標是「保存」所需的操作符,然後將它與arr [1]和arr [2](在int運算符中顯示)放在一起,以「排序」創建整個數學運算。 但是,當我選擇一個特定的操作符時發生錯誤。
我希望得到這個幫助。謝謝!
您正在嘗試用sc.nextInt()讀取一個字符。這聽起來不對。 – sjngm 2010-12-20 14:49:13
你覺得'System.out.print(「什麼是」+運算符)'行可以打印? – SLaks 2010-12-20 14:52:53
號碼,運營商,號碼。舉個例子:10 * 10 – Racket 2010-12-20 15:13:01