Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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
  • 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.
 
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic