Jump to content
Sign in to follow this  
alienA2

Exception in thread "main" java.util.InputMismatchException

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

Share this post


Link to post
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!

  • Like 1

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...