我從輸出端得到一個錯誤消息,當我輸入:199.99異常螺紋主力」 java.util.InputMismatchException
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextFloat(Scanner.java:2388)
at myproject2.Myproject2.main(Myproject2.java:11)
,但我的代碼沒有任何錯誤:
package myproject2;
import java.util.Scanner;
public class Myproject2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter purchase amount: ");
double purchaseAmount = input.nextDouble();
double tax = purchaseAmount * 0.06;
System.out.println("Sales tax is " + (int)(tax * 100)/100.0);
}
}
請幫幫我!
嗯。堆棧跟蹤顯示「nextFloat」,但代碼顯示爲「nextDouble」。你確定堆棧跟蹤是通過運行該代碼獲得的嗎? –
您是否輸入了數字以外的其他輸入? – Vamshi
你跑哪些場所?我想知道它是否期待「199,99」。 –