I am getting an error message from the output when I typed : 199.99
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)
but my code doesn't have any errors:
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);
}
}
Please help me!
nextFloat, but your code showsnextDouble. Are you sure that stack trace was obtained by running that code?