Scanner s = new Scanner(System.in); System.out.println("请输入要插入的位置:"); int location = s.nextInt(); System.out.println("请输入要插入的元素:"); int m = s.nextInt(); //插入位置后的元素依次往后移动一位 for (int i = num1.length-1; i > location; i--) { num1[i] = num1[i-1]; } //将新元素添加到要插入的位置 num1[location] = m; for (int i = 0; i < num1.length; i++) { System.out.println("现在的数组"+num1[i]); }
Scanner s = new Scanner(System.in); System.out.println("请输入要删除的位置:"); int index = s.nextInt(); String[] tempWareHouse = new String[wareHouse.length-1]; for (int i = 0; i < wareHouse.length-1; i++) { if (i < index) { tempWareHouse[i] = wareHouse[i]; }else { tempWareHouse[i] = wareHouse[i+1]; } } System.out.println("删除该货品品后的仓库:"); for (int i = 0; i < tempWareHouse.length; i++) { System.out.println(tempWareHouse[i]); }