This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Confused  in console please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Confused  in console please help" Watch "Confused  in console please help" New topic
Author

Confused in console please help

Rajat kumar jain
Greenhorn

Joined: Dec 22, 2011
Posts: 25
Hello all please help me in one of my doubt

actually i was writing a program in which a program has to take 3 numbers from the user and if i will not enter the third number and just press enter key then it should multiply first two numbers else it should multiply all the three numbers and show the result.
Now the problem is that
i use following statement
DataInputStream dis=new DataInputStream(System.in);
String r=dis.readLine();

now the problem is that if i dont write anything on the console and simply press enter then what would it consider it whether it will consider it as null string(r==null) or anything else as in the following code it always excecutes if statement please reply asap guys


Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Did you try add && r.length() > 0 to your if condition?


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Confused in console please help
 
Similar Threads
To validate telnet connectivity in java code
Switch-Case
How to reiterate a do while loop after an exception is caught, run time error handling issue
How to ask for user input twice?
an int and a string.