• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Help  RSS feed

 
Ronan Leonard
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was compiling the following code:
public class Board {
private int xSize, ySize;
Square squareFinder[];

public void setSize(int x, int y){

xSize = x;
ySize = y;
squareFinder = new Square[x*y];
}
for(int i = 0; squareFinder.length > i; i++){
squareFinder[i] = new Square();

}

boolean selectEdge(int x_box, int y_box, int sideofBox){
squareFinder[(xSize)*y+x].SelectEdge(sideofBox);


}


public String toString(){


}
}
But 4 errors Board.java:11: illegal start of type
for(int i = 0; squareFinder.length > i; i++){
^
Board.java:11: <identifier> expected
for(int i = 0; squareFinder.length > i; i++){
^
Board.java:11: <identifier> expected
for(int i = 0; squareFinder.length > i; i++){
^
Board.java:11: <identifier> expected
for(int i = 0; squareFinder.length > i; i++){
^
keep coming up.Why?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You closed the brace, ending the method, on the line above. So your "for" loop is directly inside the class. You can only have variable, class and method declarations directly inside a class. You probably want to move that brace down a bit.

Use an editor or IDE that automatically looks after the indentation of your code, then you'll see this type of mistake more easily.

Also, please use CODE tags when you post here.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!