Jump to content

Exception in thread "main" java.util.InputMismatchException


alienA2
 Share

Recommended Posts

Hi guys! :) This is the error message I get running the Java script I created. C:\java_prog\mywork\RW2D>java rw2dException 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.nextDouble(Scanner.java:2456) at rw2d.main(rw2d.java:22) Script below: import java.util.Scanner;import java.io.File;import java.io.FileNotFoundException;import java.io.PrintStream;class rw2d{ //List of instructions public static void main(String args[]) throws FileNotFoundException { // Variable declarations... Scanner DS = new Scanner (new File("raw_data.txt") ); PrintStream DW = new PrintStream("edit_data.txt"); double unitprice, quantity, total; // Prompt user for data. Code below will assign the values to the appropriate variables unitprice = DS.nextDouble(); quantity = DS.nextInt(); // Calc the total total = unitprice * quantity; // Print the info/data to the output file DW.println(total); }}

  • Like 1
Link to comment
Share on other sites

If the content in your raw_data.txt is something like: 12.34 5 (tokens separated by space)Then the nextDouble() return 12.34, the nextInt() return 5main() function will run fine!
If the content in your raw_data.txt is something like: 12.34 5 (tokens separated by space)Then the nextDouble() return 12.34, the nextInt() return 5main() function will run fine!
will give it a try thanks
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...