Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". Any value that is the same as the immediately preceding value is considered a consecutive duplicate. In this example, there are three such consecutive duplicates: the 2nd and 3rd 5s and the second 6. Note that the last 3 is not a consecutive duplicate because it was preceded by a 7. Write some code that uses a loop to read such a sequence of non-negative integers , terminated by a negative number. When the code finishes executing, the number of consecutive duplicates encountered is printed. In this case, 3 would be printed. Assume the availability of a variable, stdin, that references a Scanner object associated with standard input. That is, stdin = new Scanner(System.in); is given.

Respuesta :

// Variable to keep track of array size

int length = 0;

// Array itself

int array[] = {};

// while loop will take input in the array until a negative number is entered

while(input>=0){

stdin = new Scanner(System.in);

array[length] = stdin;

length +=1;

}

// int variable to terminate while loop

int i =0;

// keep track of index of output array

int y =0;

while(arr[i] != length){

// making output array

int output[]={}; bool flag;

// put the element in out put array considering if it the desired one

output[y] = array [i];

// Now check if it was the desired?

for(int z=1;z<=length;z++){

if(array[i+z]!=output[y]){

 flag = true;

}

else

{

 output[y]=0;

 y+=1;

}

if(array[i+z+1]=output[y] && flag == true){

output[y] = array[i];

y+=1;

}

}

//output the array

for(int o=0;o<y;o++)

System.out.println(output[o];

ACCESS MORE