I’m just working on a project and I have to use eclipse to work on it. So, when I was creating a for loop, I had noticed that the ‘i’ variable had just turned blue and it returned the same Syntax error from the previous code which was Syntax error on token ";", , expected
. Here are the images to show you what I mean.
I haven’t really changed anything in Eclipse settings recently or in general concerning syntax. I have no idea why it’s being weird. I also found that when I hover over ‘i’, it shows int activities.activity1.Card.i
.
Advertisement
Answer
You are writing code directly inside a class. Any code that should be excuted is written inside a method.
In your case,
JavaScript
x
public class Cards {
//this is inside class.
for(int i=0; i<4; i++) { /*Your code*/ }
}
Change this to:
JavaScript
public class Cards {
public static void main(String[] args) {
for(int i=0; i<4; i++) { /*Your code*/ }
}
}