Himura Kenshin Posted September 30, 2004 Report Posted September 30, 2004 Need help with a program heres what i get in command prompt: Animals.java:9: unreported exception java.io.IOException; must be caught or declared to be thrownDogman(); ^ Heres my code : import java.io.*; public class Animals{public static void main(String[] args){ Dogman();System.out.println("Animal List");} public static void Dogman() throws IOException { InputStreamReader reader = new InputStreamReader(System.in);BufferedReader input = new BufferedReader(reader); System.out.println("Dog");System.out.println("Cat");System.out.println("Cow");System.out.println("Horse");System.out.println("Sheep");System.out.print("Pick an Animal:");String animal = input.readLine();String animal2 = animal.toLowerCase();{ if(animal2.compareTo("dog")==0);System.out.println("Ruff, Ruff"); }}}
»Maverick Posted October 1, 2004 Report Posted October 1, 2004 Dogman();<{POST_SNAPBACK}> Instead of this, put this in your code: try { Dogmain(); catch(IOException) { System.out.println("EEP! I/O Error encountered"); } http://java.sun.com/docs/books/tutorial/es...ial/exceptions/ -MMave
Himura Kenshin Posted October 1, 2004 Author Report Posted October 1, 2004 ok now heres another problem eww lol the error : Animals.java:10: 'catch' without 'try'catch(IOException) {^Animals.java:8: 'try' without 'catch' or 'finally'try {^2 errors and heres the code : import java.io.*; public class Animals{public static void main(String[] args){ try {Dogmain();catch(IOException) {System.out.println("EEP! I/O Error encountered");}}} public static void Dogman() throws IOException { InputStreamReader reader = new InputStreamReader(System.in);BufferedReader input = new BufferedReader(reader); System.out.println("Dog");System.out.println("Cat");System.out.println("Cow");System.out.println("Horse");System.out.println("Sheep");System.out.print("Pick an Animal:");String animal = input.readLine();String animall = animal.toLowerCase(); if((animall.compareTo("dog")==0)) {System.out.println("Ruff, Ruff"); }}}
MikeTheNose Posted October 3, 2004 Report Posted October 3, 2004 Closed. Technical support for Subspace/Continuum.
Recommended Posts