This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of AWS Security and have Dylan Shields on-line!
See this thread for details.
Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

check for nonnumeric values entered via the java.util.scanner?

 
Ranch Hand
Posts: 62
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Was it the scan.nextLine() instead of scan.next() to discard?

Oh and the \n\n was there because I just wanted some space before it prompts "Enter a number: " again. Really just OC attack. >_<
 
Marshal
Posts: 69527
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there is a much more serious mistake, I am afraid. Chucking myScanner.next() away is the correct thing to do in those circumstances.
You can easily get two line ends like this:- System.out.printf("%s is brilliant%n%n", "Campbell");

Only you can never get anybody to read it
 
expectation is the root of all heartache - shakespeare. tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic