Given a sequence of numbers like this:
1 2 2 5 5 5 1 7 3 7 7 7
Output should be
1 2 5 1 7 3 7
The current output of my code is
1 2 5 1 7 3
I am unable to fix the problem. Can anyone tell me what should I do or change in my code?
Here's my current code:
public class Q3 {
public static void main(String args[]) {
int [] input=new int[]{1 ,2, 2, 5, 5, 5, 1, 7, 3, 7, 7, 7};
int current= input[0];
boolean found=false;
for(int i=0; i< input.length; i++) {
if(current == input[i] && !found) {
found=true;
} else if(current!=input[i]) {
System.out.print(" " + current);
current=input[i];
found=false;
}
}
}
}