2 odpowiedzi
+ 1
You are declaring y within the scope of your for loop.
You write the loop like this:
for(int y = 4; y <= 12; y = y+4)
System.out.println(y);
System.out.println(y);
When you use no brackets in a loop, only the first statement after it belongs to the loop.
When you try to print y a second time, the loop is already over, the variable y forgotten.
So you get an error - y doesn't exist.
If you want to include more than one statement in a loop, you need brackets.
Write like this:
for(int y = 4; y <= 12; y = y+4) {
System.out.println(y);
System.out.println(y);
}
0
Thank yoo so much