15th Mar 2021, 9:18 PM
Vikash Kumar Tiwari
Vikash Kumar Tiwari - avatar
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); }
15th Mar 2021, 10:45 PM
HonFu
HonFu - avatar
0
Thank yoo so much
15th Mar 2021, 10:49 PM
Vikash Kumar Tiwari
Vikash Kumar Tiwari - avatar