2 Answers
+ 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
Hot today
Python — File Handling
2 Votes
Help me
0 Votes
What’s wrong?
2 Votes
Question is write a c program to print prime numbers up to n and print the largest number in array.
1 Votes
Achievements on Sololearn
1 Votes
How to draw in the console?
0 Votes