Results 1 to 4 of 4
  1. #1
    littlebirdpoo is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default 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!

  2. #2
    Mapisto is offline Senior Member
    Join Date
    Dec 2011
    Posts
    102
    Rep Power
    0

    Default 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];

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,436
    Blog Entries
    7
    Rep Power
    20

    Default Re: Question about Keyboard input

    Quote Originally Posted by littlebirdpoo View Post
    Java 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
    Last edited by Norm; 12-17-2011 at 03:38 PM. Reason: Moved the '10' outside of []s
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    littlebirdpoo is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Re: Question about Keyboard input

    Thanks guys!
    I solved the problem!!!
    :)

Similar Threads

  1. Read input from keyboard
    By bison in forum New To Java
    Replies: 2
    Last Post: 11-20-2010, 06:48 PM
  2. How to use another image using a keyboard input
    By Rekuta in forum New To Java
    Replies: 0
    Last Post: 05-13-2010, 05:00 PM
  3. get keyboard input while running in the background?
    By gen1mx6 in forum Advanced Java
    Replies: 16
    Last Post: 07-16-2009, 03:51 PM
  4. Basic keyboard input and edit
    By BHCluster in forum New To Java
    Replies: 18
    Last Post: 08-08-2008, 11:52 PM
  5. Polled keyboard input through swing
    By Prometheus in forum Advanced Java
    Replies: 2
    Last Post: 02-04-2008, 04:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •