Sorry if this question was asked (probably many times), but I couldn't find an answer. I'm learning Java and I've made a simple code. It's asking for 2 numbers, comparing it and uses If to give some results. It's working good, but I try to loop it. gram is in loop while i give first number value as 10. This won't work like this, because "First cannot be resolved to a variable" because it's inside a loop. Ok I understand, but is there any way I can make this work with variable inside loop ?
import java.util.Scanner;
public class Loop {
public static void main(String[] args) {
do {
System.out.println("give me 2 numbers: ");
String FirstNum, SecNum;
Scanner FirstRead = new Scanner(System.in);
Scanner SecRead = new Scanner(System.in);
FirstNum = FirstRead.nextLine();
SecNum = SecRead.nextLine();
int First = Integer.parseInt(FirstNum); // changing String to int
int Second = Integer.parseInt(SecNum); // changing String to int
// Playing with loop
if (First == Second) {
System.out.println("First " + First + " is same as "+ Second);
}
else {
System.out.println("Number " + First + " is different then " + Second);
}
}
while(First == 10);
System.out.print("We're done here, because first number is 10");
}
}