Welcome to the Ranch! Please UseCodeTags (<- read) when posting your code. I have added them for you this time.
As per your question, the first thing you did wrong is the line 19 of your code - you are trying to compare two object references, both of which are of String type. Since these are not the same, you are always getting false as a result, hence the output you get.
However, the approach is still wrong, even if the above wouldn't be a problem. I would recommend you read Regular Expressions tutorial to get an idea on how to use them. As a hint, for your problem you would probably need to check String#replaceAll() method.
The quieter you are, the more you are able to hear.
Joined: May 21, 2013
Thank you Kemal,
So basically, I need to get a more solid grip on RegEx before I try this stunt!
What I did was tried to use an Eclipse plugin, named QuickREx, where I got the said RegEx and tried to plug that in my code!
But I will try that tutorial first and if still unclear, will head back to moose!
Thank you, also, for the code tags and I can now see why you use it!
Nikhil Shanbhag wrote: . . . Its just that I was trying various permutations and combinations . . .
Trying various things sounds to me like a policy for disaster; you can try 1000000 things and maybe one will work, or you can learn to do it correctly and your first attempt will work.
I would suggest hasNextInt, as previously mentioned, may be the best solution. In my opinion, it would be better still if you wrote a utility class to use that Scanner in.
If you insist on using regexes, try a tutorial, so you know how to use them, and it will work nicely.