• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cant compile the program

 
jo sim
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi here is the code that i am trying to compile I am trying to assign p to the index 00 and want to put it in the method and print the value in class k. can someone tell me what can i do so it does that?

class j
{
String[][] first = new String[1][3];
first[0][0]= "p";
void method(){
System.out.println(first[0][0]);

}
}


class k{
public static void main(String[] args){
j one = new j();
one.method();

}
}
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java, you can't have the assignment first[0][0]=p where you wrote it. It has to be within a method, a constructor etc... for example, here it is, placed in a constructor:
 
jo sim
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much that solved the problem
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic