X Question 2 of 2 Question 2 (3 Unlimited tries Consider this data sequence: "3 11 5 55246673-8". Any value that is the
Posted: Tue May 24, 2022 8:11 am
Question 2 of 2 Question 2 (3 Unlimited tries Consider this data sequence: "3 11 5 55246673-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. 1 2 = 0; int count - 0, n = 0, num, prev= 0, pprev while (in.hasNextInt ()) { 3- 4 num= in.nextInt (); 5 n++; 6 if (num < 0) break; 7- if (n > 1) { 8- if (prev== num && pprev= num) { ++count; } 00 9 10
X