2 回答

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個(gè)贊
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 導(dǎo)入
import java.util.Arrays;
import java.util.Scanner;

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超9個(gè)贊
Array1在 reading 后面移動(dòng)(并重命名)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;
添加回答
舉報(bào)