I am creating a program that removes duplicate values based on 10 user inputs. However instead of having distinct values such as [1,2,3,4,5,6] I have zeros in my output as such [0, 1, 0, 2, 0, 3, 0, 4, 5, 6]. Some kind assistance on this matter would be greatly appreciated!
import java.util.*;
public class SOB23_2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner sc= new Scanner(System.in);
int[]Array= new int[10];
for(int i=0;i<Array.length;i++)
{
System.out.println("Enter number"+(i+1)+":");
Array[i]=sc.nextInt();
}
System.out.println("The distinct values of the array are"+Arrays.toString(eliminateDuplicates(Array)));
}
public static int[]eliminateDuplicates(int[]list)
{
int [] temp=new int[list.length];
for(int i=0;i<list.length-1;i++)
{
if(list[i]!=list[i+1])
{
temp[i]=list[i];
}
}
temp[list.length-1]=list[list.length-1];
return temp;
}
}