I'm stuck on an error for hours while practising Java. When I enter the price with decimal points I get this Error
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextDouble(Scanner.java:2413)
at grocerystore.GroceryStore.main(GroceryStore.java:19)
C:\Users\aslan\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53:
My code:
package grocerystore;
import java.util.Scanner;
/**
*
* @author aslan
*/
public class GroceryStore {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
double [] prices = new double [5];
Scanner in = new Scanner(System.in);
System.out.println("Enter 5 prices: ");
prices[0] = in.nextDouble();
prices[1] = in.nextDouble();
prices[2] = in.nextDouble();
prices[3] = in.nextDouble();
prices[4] = in.nextDouble();
double total = prices[0] + prices[1] + prices[2] + prices[4];
System.out.printf("the tot1al of all 5 items is:$%5.2f" +total);
}
}
Can any one help ???