This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to "throw an exception?"" Watch "How to "throw an exception?"" New topic
Author

How to "throw an exception?"

Ashley Kin
Ranch Hand

Joined: Oct 18, 2011
Posts: 36
Hello, I wrote this code that takes values as input from a user until a negative number is entered, and then prints the average of those values, not including the negative number.
I need to figure out how to not print an average if the first number a user inputs is negative. I think I should "throw an exception," but I'm not really sure how to go about that.
Thanks!

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Not really sure? Then since you want to know about exceptions, your google keywords should be "java exception tutorial".

The first link you get back should be Oracle's tutorial (have a look at the URL to make sure). Read it: Lesson: Exceptions.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to "throw an exception?"
 
Similar Threads
How to write an algorithm for an average of values?
jar
problem with while loop
Error incrementing value in catch block
what's wrong with the for-each