![]() |
| ||
| error checking I would like to make so that when you have a int and prompting user to enter some number for calculations... if the number entered is larger than a 10digits, my program wouldn't just crash or if the user enters a string... I havn't be taught any error catching stuff yet but it would be good to have my simple command line program to run without crashing... Thanks. |
| ||
| Re: error checking import java.util.Scanner; I've been reading the api and a tutorial, I don't understand how to use what's described in the api and my loop isn't working correctly for the other tutorial... Bascially I want to enter 10 number but with some sort of error checking and keep prompting to enter the 10 number if any of them is invalid... I havn't done, throws and try catch in my study so I'm not even sure I've used them right. http://java.sun.com/j2se/1.5.0/docs/...Exception.html http://www.deitel.com/articles/java_...ons/index.html |
| ||
| Re: error checking using try and catch is an easy, but on the other hand definitive way to catch your error. your program will not crash, but if you make a wrong input, your program won't ask for any more. for instance: int numbers[] = new int[5]; try{ for(int count = 0; count < 5; count++){ numbers[count] = readNumber(); } } catch(Excetion ex){ // this is the part that would happen if an invalid value (maybe a // String Object) was entered in case of a number. } everything behind the catch clause is runned both when an error occured, and when no error occured. if you want now to add all the numbers to one huge sum, you must remember that there is a possibility that not all the elements of the array contain the values you want them to contain |
| All times are GMT -4. The time now is 7:59 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC