How do I fill an array with consecutive numbers

前端 未结 6 840
感情败类
感情败类 2020-12-20 12:29

I would like to fill an array using consecutive integers. I have created an array that contains as much indexes as the user enters:

Scanner in = new Scanner(         


        
6条回答
  •  [愿得一人]
    2020-12-20 13:05

    One more thing. If I want to do the same with reverse:

    int[] array = new int[5];
            for(int i = 5; i>0;i--) {
                array[i-1]= i;
            }
            System.out.println(Arrays.toString(array));
    }
    

    I got the normal order again..

提交回复
热议问题