i need a code that inputs 10 numbers from the user, displays only the distinct numbers and the quantity of distinct numbers ("xxxx distinct #s were entered.")
I am having a hard time displaying the quantity of distinct numbers.
import java.util.Scanner;
class hwFINAL {
public static void distinctElements(int[] array){
int count=0;
int i=0;
for(i=0;i<array.length;i++){
boolean isDistinct = false;
for(int j=0;j<i;j++){
if(array[i] == array[j]){
isDistinct = true;
break;
}
}
if(!isDistinct)
System.out.print(array[i]+",");
}
}
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int arr[] = new int[10];
for (int i = 0; i < arr.length; i++) {
System.out.print("Enter numbers " + (i+1) + " : ");
arr[i] = scan.nextInt();
}
for (int i = 0; i < arr.length; i++);
hwFINAL.distinctElements(arr);
}
}