Heute war ich versucht, eine grundlegende Übung zu tun und ich in diesem Problem konfrontiert:Java Problem mit Eingabe
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at Main.main(Main.java:14)
Dies ist der Code:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double salary = 0; // Salary excluded tax
int tax = 0; // % of tax
double taxTot = 0; // amount of tax
double totSalary = 0; // Salary with tax
System.out.println("Salary, please : "); //Input salary
salary = input.nextDouble();
if (salary <= 15000) { // <=15000
tax = 10;
} else if (salary>= 40000 && salary < 60000){ // >=40000
tax = 20;
} else { // over > 60000
tax = 30;
}
taxTot = salary/100*tax;
totSalary = salary - taxTot;
System.out.println("Your tax is : " + taxTot + " Your salary : " + totSalary);
}
}
ich kompiliert und lief das Programm. Ich habe keinen Fehler, als ich eine Nummer eingegeben habe. Bei der Eingabe eines Buchstabens habe ich jedoch denselben Fehler wie Sie, was nicht überraschend ist. Was ist dein Beitrag? – Gendarme
Ich kann nicht scheinen, Ihr Problem zu replizieren. kopieren und einfügen und es funktioniert gut für mich. –
Welche Art von Eingaben geben Sie beim Ausführen dieser Anwendung an? – LearningPhase