Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

question about input being null and how to "catch" it

807589Nov 18 2008 — edited Nov 18 2008
I've got a program that takes an integer using Scanner's nextInt() method. If the user doesn't enter anything, my program ~!@#$%^&*()_ up.
I tried two things:
1.
int num = myScanenr.nextInt();
if(num==null)
     System.exit(0);
this wouldn't compile because the type were incomparible

2.
Scanner myScanner = new Scanner(System.in);
if(myScanner==null)
   System.exit(0);
this had no effect on my program

does the scanner take the input even before nextInt() is called, or is my thinking in error?
how do I solve my problem about empty input?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 16 2008
Added on Nov 18 2008
3 comments
515 views