I want to create a public string variable in a for loop that I can use even outside of it.I know that this is possible in C# just by marking the string as public, bt doing the same thing in Java doesn't seem to do the trick. Any suggestions?
for (int i = 0; i < answerList.size(); i++) {
System.out.println(answerList.get(i).q);
answerList.get(i).spot = i;
System.out.println(answerList.get(i).spot);
switch (answerList.get(i).spot) {
case 0:
if(answerList.get(i).correct = true) {
String correctAns = "a";
String correctAnsVariantTwo = "A";
break;
}
case 1:
if(answerList.get(i).correct = true) {
String correctAns = "b";
String correctAnsVariantTwo = "B";
break;
}
case 2:
if(answerList.get(i).correct = true) {
String correctAns = "c";
String correctAnsVariantTwo = "C";
break;
}
case 3:
if(answerList.get(i).correct = true) {
String correctAns = "d";
String correctAnsVariantTwo = "D";
break;
}
}
}
Scanner a = new Scanner(System.in);
String ats = a.nextLine();
if(ats.equals(correctAns)) {
//do something
}