X Question 2 of 2 Question 2 (3 Unlimited tries Consider this data sequence: "3 11 5 55246673-8". Any value that is the

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

X Question 2 of 2 Question 2 (3 Unlimited tries Consider this data sequence: "3 11 5 55246673-8". Any value that is the

Post by answerhappygod »

X Question 2 Of 2 Question 2 3 Unlimited Tries Consider This Data Sequence 3 11 5 55246673 8 Any Value That Is The 1
X Question 2 Of 2 Question 2 3 Unlimited Tries Consider This Data Sequence 3 11 5 55246673 8 Any Value That Is The 1 (57.59 KiB) Viewed 12 times
X 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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply