Hello guys I am trying to play with try and catch but i cannot get the results that I want. Hope you will help me out.
Here's the program:
What I want to do is catch and print error if the user input an integer. But in the progam even thou i input an integer it will still pint it. Can you please help me? I have not taken his topic before because i am a very much newbie with java.
Thanks
Ernest Friedman-Hill
author and iconoclast
Marshal
Nothing in your program will actually throw a NumberFormatException, so you won't ever catch one. NumberFormatException is thrown by methods that want a string to contain an integer, if it turns out that the string doesn't. For example, the "Integer.valueOf()" will throw an exception here, and the catch block will execute:
Originally posted by Ernest Friedman-Hill: Hi Beth,
Nothing in your program will actually throw a NumberFormatException, so you won't ever catch one. NumberFormatException is thrown by methods that want a string to contain an integer, if it turns out that the string doesn't. For example, the "Integer.valueOf()" will throw an exception here, and the catch block will execute:
Hello ma'am,
May I know what should i do so my program can catch integer entered? What i want my program to do is accept string not integer but it still accept integers. Is there a way? Thanks
May I know what should i do so my program can catch integer entered? What i want my program to do is accept string not integer but it still accept integers. Is there a way? Thanks
Surely you're not calling Ernest ma'am?? Dr. Friedman-Hill is quite male indeed
If you want to disallow numbers then you should do it the other way around: try parsing the name into an integer, and if that fails then it's a GOOD thing:
Originally posted by GUNA RANJAN: Hey Beth Laguardia wont my coding is not working for You ! i hope you may not run the coding ! well anyway i said my suggestion its up to You ! bye !!
Hey Gina I am sorry. I thought the code you posted is yours and you are having a hard time also. Will try all the sugestion here. Its the only way I can learn..
Thanks a lot
Beth Laguardia
Ranch Hand
Joined: Jun 01, 2008
Posts: 34
posted
0
Thank you all sir!
Will try all the codes and study it. Really thanks a bunch!