Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
nextInt存储在Java数组中_Java - Fatal编程技术网

nextInt存储在Java数组中

nextInt存储在Java数组中,java,Java,所以我有这个代码: int[] player1 = new int[5]; // first player try{ for(int i=0;i<5;i++) { player1[i] = keyin.nextInt();} } catch(NumberFormatException e){ System.out

所以我有这个代码:

int[] player1 = new int[5]; // first player
            try{

               for(int i=0;i<5;i++) {

                   player1[i] = keyin.nextInt();}
               }
           catch(NumberFormatException e){

               System.out.println("Player 2 : ")

           }
int[] player2 = new int[5]; // Second Player

                try{

               for(int i=0;i<5;i++) {

                   player2[i] = keyin.nextInt();}
               }
           catch(NumberFormatException e){

               System.out.println("Player 3 : ");  
           }                  
int[]player1=新int[5];//第一名选手
试一试{

for(inti=0;i使用for循环请求用户输入5个数字

for(int i=0;i<5;i++) {

                   player1[i] = keyin.nextInt();}
               } 

然后使用一个if语句,一旦输入达到5个字符,或者如果用户通过按键盘上的一个键来跳出循环。

nextInt
后面应该跟着
nextLine
,以删除仍保留在
系统中的回车符。
缓冲区中…否则
nextInt
将在下次启动时失败called@MadProgrammer我该怎么写呢?(新手程序员!)
keyin.nextLine()
…@MadProgrammer你说后面跟着nextLine?对不起,复制并粘贴我正在尝试这样做,用户只需按int以外的任何东西,它必须看起来像
Player1:1234
,在下一行
Player2:3221
我会将while循环放在for循环之外?
while(keyin.hasNextInt()){

}