package cn.jxxy.chapter01;public class RemoveDuplicateDemo { public static void main(String args[]) { int[] numbers = new int[10]; java.util.Scanner input = new java.util.Scanner(System.in ); System.out.print("Enter ten numbers: "); for (int i = 0; i < numbers.length; i++) { numbers[i] = input.nextInt(); } int[] result = removeDuplicate(numbers); System.out.println( "The number of distinct values is " + result.length); for (int i = 0; i < result.length; i++) System.out.println(result[i] + " "); } public static int[] removeDuplicate(int[] numbers) { System.out.println("The distinct numbers are:"); int[] removeDuplicate= {1,1,1,1,1,1,1,1,1,1}; for(int i=0; i < numbers.length;i++) { for(int j=9; j > numbers.length-1; j--) { if(numbers[i]==numbers[j]) { removeDuplicate[j]=-1; } } for(int i=0;i<numbers.length;i++) { if(removeDuplicate[i]==1) { System.out.print(numbers[i]+""); } } }
添加回答
举报
0/150
提交
取消