我试图得到一堆数字作为输入,并输出它作为第一个未排序的数组,然后排序。如何将输入值存储在for循环内的数组中?现在,它只存储最后输入的值。如何将值存储在for循环中的数组中?
String strNumberOfValues, strValue;
int intNumberOfValues, intValue;
Scanner input = new Scanner(System. in);
System.out.println("Please enter the number of values you would like to enter");
strNumberOfValues = input.nextLine();
intNumberOfValues = Integer.parseInt(strNumberOfValues);
for (int i = 0; i < intNumberOfValues; i++) {
System.out.println("Please enter value for index value of " + i);
strValue = input.nextLine();
intValue = Integer.parseInt(strValue);
for (int j = 0; j == 0; j++) {
int[] intArray = {
intValue
};
System.out.println("Here is the unsorted list: \n" + Arrays.toString(intArray));
究竟为什么你重新职位,给予近三分钟前一个答案? – Turing85
:-)我在5分钟之前开始回答这个问题。但格式化需要更多时间。 – ganeshvjy