This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
answer for try and catch
Posted by Y.M.Sudarsan on August 07, 2000 at 11:10 AM
> I entered a simple program because it uses a try and catch > statement and I have no experience with the two. Here's the code > as seen in the book. It throws two errors and I cannot find the > answer. Give a holler if you see anything wrong with the code. > Thanks, Steve: > public class Fruit > { > public static void main(String[] args) > { > int numOranges = 5; > int numApples = 10; > int numFruit = 0; > > numFruit = numOranges + numApples; > System.out.println("A totally fruity program."); > System.out.println("Total fruit is " + numFruit); > > System.out.println("(press ENTER to exit)"); > try > { > System.in.read(); > } > catch (IOException e) > { > return; > } > } > } > The errors are: > 17: Exception java.io.IOException must be caught, or it must be > declared in the throws clause of this method. > System.in.read(); > ^ > 19: Class IOException not found. > catch (IOException e) > ^ Dear steve, type this first : import java.io.*; then type type the rest of the code. Your program will compile and execute correctly
Replies:
|