This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes How Can I do it without using if condition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How Can I do it without using if condition" Watch "How Can I do it without using if condition" New topic
Author

How Can I do it without using if condition

Bhairava Surya
Ranch Hand

Joined: Aug 19, 2007
Posts: 45
Hi All,

Consider a program accepts inputs like '4', or some string etc.

Using exceptions concept how can i display whether the input is number or string.. without using 'if condition'??

Thanks & Regards,
Ravi.
S. Nitesh
Ranch Hand

Joined: Jan 15, 2010
Posts: 36
    
    1


I think, this should work.
Bhairava Surya
Ranch Hand

Joined: Aug 19, 2007
Posts: 45
Hi Nitesh,

Thanks for your immediate reply. But, can you give a complete code without if condition.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3482
    
  13
Which bit are you having a problem with ? Put that line of code in a try/catch block, add a couple of print statements and you're done. Give it a try. You'll learn more by trying it yourself than having the code given to you.


Joanne
S. Nitesh
Ranch Hand

Joined: Jan 15, 2010
Posts: 36
    
    1

Chinna,
Did you work on Joanne's suggestion?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How Can I do it without using if condition