public class remove { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println("please input a order:"); int []a=new int[5]; for (int i = 0; i < a.length; i++) { a[i]=input.nextInt(); } System.out.println("please input a val:"); int val= input.nextInt(); int i = removeElement(a, val); System.out.println("删除后有"+i+"个元素"); for (int j = 0; j < i; j++) { System.out.print(a[j]+" "); } } public static int removeElement(int[] nums, int val) { if(nums.length==0||nums==null) { return 0; } int j=0; for(int i=0;i<nums.length;i++) { if(nums[i]!=val){ nums[j++]=nums[i]; } } return j; } }