Why on earth does the catch statement return an error? It's pretty much cut and paste from a java schoolbook! What the program does isn't all that important, without the try/catch, the code compiles fine... But as soon as the catch is introduced, I get an error saying "cannot find symbol," on line 23, the catch line.
[CODE=java]
import java.util.Scann er;
public class O2a{
public static void main (String[] args){
Scanner scan = new Scanner(System. in);
while (true){
System.out.prin tln("\nPlease enter two integers ");
try{
int a=scan.nextInt( );
int b=scan.nextInt( );
// Solution:
System.out.prin tln("a + b = " + (a+b));
System.out.prin tln("a - b = " + (a-b));
System.out.prin tln("a * b = " + (a*b));
System.out.prin tln("a / b = " + (a/b));
System.out.prin tln("a % b = " + (a%b));
System.out.prin tln("(a / b) * b + a % b = " + (a+(a%b)));
}
catch (InputMismatchE xception exception){
System.out.prin tln("Are you trying to quit the program? (y/n) ");
String inAnswer=scan.n extLine();
if (inAnswer=="n") {
continue;
}
else if (inAnswer=="y") {
break;
}
}
finally{
continue;
}
}
}
}[/CODE]
[CODE=java]
import java.util.Scann er;
public class O2a{
public static void main (String[] args){
Scanner scan = new Scanner(System. in);
while (true){
System.out.prin tln("\nPlease enter two integers ");
try{
int a=scan.nextInt( );
int b=scan.nextInt( );
// Solution:
System.out.prin tln("a + b = " + (a+b));
System.out.prin tln("a - b = " + (a-b));
System.out.prin tln("a * b = " + (a*b));
System.out.prin tln("a / b = " + (a/b));
System.out.prin tln("a % b = " + (a%b));
System.out.prin tln("(a / b) * b + a % b = " + (a+(a%b)));
}
catch (InputMismatchE xception exception){
System.out.prin tln("Are you trying to quit the program? (y/n) ");
String inAnswer=scan.n extLine();
if (inAnswer=="n") {
continue;
}
else if (inAnswer=="y") {
break;
}
}
finally{
continue;
}
}
}
}[/CODE]
Comment