For some reason even when I initialise the variable outside of the for loop, my code will not compile...
public static void main(String[] args) {
int x;
for (int i = 0; i < 4; i++){
x = 10;
}
System.out.println(x);
}
I get the error:
error: variable x might not have been initialized
System.out.println(x);
any help will be much appreciated as i know the answer is going to be so simple.