This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confused in console please help

 
Rajat kumar jain
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9527
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try add && r.length() > 0 to your if condition?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic