How do you pass in an array from the main method to another method in java? -
i have array of person in main method, , have pass in array playgame() method in class game. how do that?
public class rolloff { public static void main(string[] args) throws ioexception{ int numpeople; int a; system.out.println("how many people play game?"); bufferedreader br = new bufferedreader(new inputstreamreader(system.in)); string s = br.readline(); numpeople = integer.parseint(s); if ((numpeople >= 2) && (numpeople <= 10)) { person[] p = new person[numpeople]; (a = 0; < numpeople; a++) { p[0] = new person(a); } } } } public class game extends rolloff{ int numpeople; int a; void playgame() { } }
you need use parameters that:
void playgame(person[] p){ ... }
now call
public static void main(string[] args){ ... game.playgame(p); }
because playgame not static method, you'll either need make static , call game.playgame(p)
or you'll need create instance of game: game game = new game()
followed call of game
, shown in example above.
Comments
Post a Comment