publicclassPaiXuAdd{ publicstaticvoidmain(String[] args){ int num[] = {1,3,5,6,7,9}; Scanner in = new Scanner(System.in); System.out.print("Input Num:"); int Num = in.nextInt(); num = Arrays.copyOf(num,num.length+1); //复制新的数组+1 num[num.length-1] = Num; //将输入的值赋值给数组的最后一位 for (int x:num) { System.out.print(x); }; } }
publicclassPaiXuAdd{ publicstaticvoidmain(String[] args){ int num[] = {1,3,5,6,7,9}; Scanner in = new Scanner(System.in); System.out.print("Input Num:"); int Num = in.nextInt(); num = Arrays.copyOf(num,num.length+1); num[num.length-1] = Num; int i = 0; if(num[i] <= num[num.length-2]) { Arrays.sort(num); //排序 } for (int x:num) { System.out.print(x); }; } }