0

Hi I'm trying to create an array of objects and then put a different value into each object. Problem is, I don't know why this isn't working.

public class TestProg2{
  public static void main(String args[]){
    Rank rank= new Rank();
  }  
}

class Rank{
private static int rankIndex=0;

public Rank(int enterRankIndex){ rankIndex=enterRankIndex; }

Rank [] ranks = new Rank [13];
for(i=0;i<ranks.length;i++) {
  ranks[i]=new Rank(i);
  System.out.println("create Rank marker:"+ranks[i]);
} 
}

I keep getting these errors:
2 errors found:
File: /Volumes/LA-PUBLIC/TestProg2/TestProg2.java [line: 13]
Error: illegal start of type
File: /Volumes/LA-PUBLIC/TestProg2/TestProg2.java [line: 16]
Error: <identifier> expected

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by Ezzaral
0

Your for() loop is not in a block. That code needs to be inside a constructor, method, or static initialization block.

Edited by Ezzaral: n/a

0

My guess would be...

public Rank(int enterRankIndex){ rankIndex=enterRankIndex; [B][U]}[/U][/B]

Edited by hfx642: n/a

0

Well yes... that would be the character that caused the problem I tried to point out to him yesterday. Evidently the OP didn't care enough to return to the thread.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.