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. 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.

Respuesta :

Answer:

int firstNumber, secondNumber, duplicates;

secondNumber = duplicates = 0;

firstNumber = stdin.nextInt();

while (stdin.hasNextInt() && firstNumber > -1 && secondNumber > -1)

{

   secondNumber = stdin.nextInt();

   if (firstNumber == secondNumber)

   {

       duplicates++;

   }

   firstNumber = secondNumber;

}

System.out.println(duplicates);

Explanation:

The code is in JAVA.

ACCESS MORE