Jump to content
SubSpace Forum Network

Recommended Posts

Posted

Need help with a program heres what i get in command prompt:

 

Animals.java:9: unreported exception java.io.IOException; must be caught or decl

ared to be thrown

Dogman();

^

 

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");

 

}

}

}

Posted

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");

 

}

}

}

Guest
This topic is now closed to further replies.
×
×
  • Create New...