• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Scanner Class,InputMatchException

 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Scanner sc=new Scanner("sue3,true3;").useDelimiter(";");
int h=sc.nextInt();

In above example and does Scanner object always ,throw
an InputMismatchException ,if not able to extract the token out of string based on regex.
Means if no match ,we will get Exception.
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi !!!

The Mehod nextInt() will always throw a InputMismatchException if the next token does not match the Integer regular expression, or is out of range.

In your code the next token is "sue3,true3" and it's not an integer. So it will throw a InputMismatchException.
 
reply
    Bookmark Topic Watch Topic
  • New Topic