Jump to content

Exception in thread "main" java.util.InputMismatchException


alienA2

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); }}

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...