简体   繁体   中英

How can i set an array length by user

i'm trying to set by user input an array length in java and put inside the array a list of Names. The problem is set when it's start the "for" cycle. It's seems that the programm can't go inside this cycle. I'm posting the code where I have got trouble. Please help me how to solve this problem

 int numPlayer = 0;
 String [] listaNomi = new String []{};
 numPlayer = myInput.nextInt();
  for (int i=0; i<numPlayer; i++)
        {
            byte num=1;
            System.out.println("Inserisci il nome del " +num);
            System.out.print("Giocatore");
            num++;
            Nome = myInput.nextLine();
            Nome = listaNomi[i];
        }

Thanks

Try putting "byte num = 1" outside of the for loop. By putting it inside the loop each time the loop runs, the variable is redefined.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM