Re: Newbie question on stopping an application



Cardinal wrote:
[...]
The difficulty I'm having is that if
someone enters a negative number, I want the program to reply something
like "Does not accept negative numbers!" then stop. I tried using
"break;" but it generated an error message and said that I was using it
"outside the loop" or something like that.
"break" is for exiting a loop, not for exiting the whole application.
I would be grateful if
someone could give me a clue on what I might use for this. Thank you
very much. My code is below.
[...]

if (cost <= 0) { //I want the program to say "You can't enter a negative number."
System.out.println("You can't enter a negative number.");
//Then the program should stop execution.
System.exit(1);
}
[...]

--
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

.