• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Help

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic