Results 1 to 4 of 4
  1. #1
    gnbradford is offline Member
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Default InputMismatchException

    Working my way thru a basic java programing book I came across a strange problem . Trying to get keyboard input through scanner I get a InputMismatchException when I enter 2dot5 ( 2.5 ) but it takes it as a double when I enter 2comma5 (2,5). Anybody know what could be happening?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: InputMismatchException

    This sounds like an issue with the locale used by your Scanner object. Consider changing this by calling .useLocale(...) on your Scanner object, using a locale that is more in line with your desired numeric format.

    i.e.,

    Java Code:
    Scanner myScanner = new Scanner(System.in);
    myScanner.useLocale(Locale.US); // for United States-compatible number formatting

  3. #3
    gnbradford is offline Member
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Default Re: InputMismatchException

    Thank you that did it. I am a gringo living in Peru.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Replies: 1
    Last Post: 09-20-2012, 10:54 AM
  2. InputMismatchException
    By jihad in forum New To Java
    Replies: 5
    Last Post: 12-17-2011, 04:10 PM
  3. Replies: 2
    Last Post: 02-11-2011, 10:03 AM
  4. try-catch InputMismatchException in a while loop
    By themulator in forum New To Java
    Replies: 17
    Last Post: 10-12-2010, 05:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •