print out the numbers that are NOTrepeated
int other words if the user inputs uni[] = {1,2,4,2,5}
the 2 will not be printed out because its repeated
here is what I got so far:
import java.util.*; public class Ejer4 { public static void main(String args[]){ Scanner reader = new Scanner(System.in); int[] uni = new int[5]; int [] apples = new int[5]; int var = 0; for(int i = 0; i<5; i++){ System.out.println("Input a number: "); uni[i] = reader.nextInt();} for(int y = 0; y<uni.length-1;y++){ if(uni[y] != uni[y+1]){ apples[y] = uni[y]; } } for(int j=0; j<apples.length;j++) System.out.println("The non-repeating numbers are: " + apples[j]); } }
It works kind of well but it still prints out one of the repeated numbers
which isnt good, and also it prints out 0 at the end and
0 in place of the repeated number its understandable given that
the array has a fixed size.. so I hope I get some help.. thanks