I have recently started to learn programming in java and in the program below I'm trying to print distinct array elements Like e.G if an int arr[]={2,5,4,9,3,2,5,9,4} then I want to be able to get the numbers only once i.e., expected value 2 5 4 9 3 Below is my code to do this but I'm getting incorrect o/p My o/p: 2 5 4 9. Can anyone point me out what am I doing wrong
package prac;
public class RemoveDup {
public static void main(String[] args) {
int[] a={2,5,4,9,3,2,5,9,4};
int n=a.length;
for(int i=0;i<=n;i++){
//System.out.print("In i"+i);
for(int j=i+1;j<n;j++){
//System.out.println("In j"+j);
if(a[i]==a[j]){
System.out.println(a[i]);
}
}
}
}
}