import java.util.Scanner;
public class Application {
public static void main(String[] args) {
do {
System.out.println("What is the command keyword to exit a loop in Java?\na. int\nb. continue\nc. break\nd. exit\nEnter your choice");
Scanner ans = new Scanner(System.in);
char ans = sc.next().charAt(0);
if(ans=='c')
System.out.println("Correct");
else
System.out.println("Wrong! Presss Y to try again.");
Scanner redo = new Scanner(System.in);
char redo = sc.next().charAt(0);
}
while(redo=='y');
}
}
I'm just starting to learn Java, can you please tell me what's wrong in my code and how to improve it? Thanks
This is the error I receive.
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Duplicate local variable ans
sc cannot be resolved
Duplicate local variable redo
sc cannot be resolved
redo cannot be resolved to a variable
at Application.main(Application.java:9)