Question about Keyboard input
public static void main(String args[])
{
Scanner keyIn = new Scanner(System.in);
double player1[], player2[], player3[], player4[], player5[], player6[], player7[], player8[], player9[], player10[] = new double [3];
System.out.print("Player 1: Enter 3 values --> ");
player1[0] = keyIn.nextDouble();
player1[1] = keyIn.nextDouble();
player1[2] = keyIn.nextDouble();
......
}
Hi guys,
new to Java, just doing a problem with keyboard input,
can someone explain why there's an error saying that player1 may not be initialized?
Thx!
Re: Question about Keyboard input
it seems to me that u need to need to put into every string a "null".
I believe (correct me if I'm wrong ppl :| ) that it is because string isn't a primitive character. with int for example it should have worked fine.
try and write :
double player1[]=null, player2[]=null, player3[]=null, player4[]=null, player5[]=null, player6[]=null, player7[]=null, player8[]=null, player9[]=null, player10[]=null = new double [3];
Re: Question about Keyboard input
Quote:
Originally Posted by
littlebirdpoo
Code:
double player1[], player2[], player3[], player4[], player5[], player6[], player7[], player8[], player9[], player10[] = new double [3];
This declaration only initializes the player10[] array while all the others will still be null. Your compiler doesn't like variables that aren't initialized.
kind regards,
Jos
Re: Question about Keyboard input
Thanks guys!
I solved the problem!!!
:)