2 回答
TA贡献1825条经验 获得超6个赞
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//int Array1[];
System.out.println("How many numaric elements: ");
int n = input.nextInt();
int arr[] = new int[n];// solve 1st problem
for (int i = 0; i < n; i++) {
System.out.println("Enter number: " +(i+1));
int number = input.nextInt();
arr[i]=number;//init array by user input data
}
System.out.println("Original numeric array : " + Arrays.toString(arr));
Arrays.sort(arr);
System.out.println("Sorted numeric array : " + Arrays.toString(arr));
}
你还需要 2 导入
import java.util.Arrays;
import java.util.Scanner;
TA贡献1799条经验 获得超9个赞
Array1在 reading 后面移动(并重命名)n:
System.out.println("How many numaric elements: ");
int n = input.nextInt();
int[] array1 = new int[n];
也许使用输入的number:
int number = input.nextInt();
array1[i] = number;
添加回答
举报