簡體   English   中英

如何由用戶設置數組長度

[英]How can i set an array length by user

我試圖通過用戶在 java 中輸入一個數組長度來設置,並在數組中放入一個名稱列表。 當它開始“for”循環時,問題就出現了。 程序似乎不能進入這個循環。 我在遇到問題的地方發布了代碼。 請幫助我如何解決這個問題

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

謝謝

嘗試將“byte num = 1”放在 for 循環之外。 通過在每次循環運行時將其放入循環中,變量被重新定義。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM