-
July 18th, 2012, 07:11 PM
#1
Throwing string exception with integers
Hello, Im looking for an example of how to throw an exception for an input string that;
rejects characters in the alphabet such as "abc..."
and only accepts numbers in the form of "1 2 3.."
Im fairly new to java and Im just looking for a solid example of this code.
-Nelson
-
July 19th, 2012, 03:10 AM
#2
Re: Throwing string exception with integers
This seems homework. Please, read this
We are here to help, not to do your homework. If we give you the answer, you'll never learn. Tell us what you tried, what you don't understand or where you are stuck, and we'll be very glad to help you.
Regards,
Albert.
Last edited by AlbertGM; July 19th, 2012 at 03:21 AM.
Please, correct me. I'm just learning.... and sorry for my english :-)
-
July 22nd, 2012, 08:06 AM
#3
Re: Throwing string exception with integers
I guess you want to filter numeric string with alphabetic String. on homework front , mods are correct but I am giving you some hint which is applicable in general.
1) There are methods in Java API which converts String to number like Integer.parseInt(String) which can throw NumberFormatException is String can not be converted into number. there are couple of more ways to do this you can also see this link http://javarevisited.blogspot.sg/201...to-string.html.
2) For getting input from user you can use java.util.Scanner class.
try working with these information and post here if you face any issue, that would improve your learning without being stuck.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|