Today I was trying to do a basic exercise and I faced in this problem :
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)
This is the 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);
}
}