Solved

Programming
Write a Static Method Named ConsecutiveDigits That Accepts an Integer

Question 5

Essay

Programming
Write a static method named consecutiveDigits that accepts an integer n as a parameter and that returns the highest number of consecutive digits in a row from n that have the same value. For example, the number 3777785 has four consecutive occurrences of the number 7 in a row, so the call consecutiveDigits(3777785) should return 4.
For many numbers the answer will be 1 because they don't have any adjacent digits that match. Below are sample calls on the method. You are not allowed to use a String to solve this problem. You may assume that the value passed to the method is greater than or equal to 0.
 Call  Returns  consecutiveDigits (0) 1 consecutiveDigits (18) 1 consecutiveDigits (394) 1 consecutiveDigits (99) 2 consecutiveDigits (8229) 2 Call  Returns  consecutiveDigits (8823) 2 consecutiveDigits (777)3 consecutiveDigits (82888)3 consecutiveDigits (7111171)4 consecutiveDigits (233333888)5\begin{array}{l|c}\text { Call } & \text { Returns } \\\hline \text { consecutiveDigits (0) } & 1 \\\text { consecutiveDigits (18) } & 1 \\\text { consecutiveDigits (394) } & 1 \\\text { consecutiveDigits (99) } & 2 \\\text { consecutiveDigits (8229) } & 2\end{array}\begin{array}{}\\\\\\\\\\\\\end{array}\begin{array}{l|c}\text { Call } & \text { Returns } \\\hline \text { consecutiveDigits (8823) } & 2 \\\text { consecutiveDigits }(777) & 3 \\\text { consecutiveDigits }(82888) & 3 \\\text { consecutiveDigits }(7111171) & 4 \\\text { consecutiveDigits }(233333888) & 5\end{array}

Correct Answer:

verifed

Verified

(one solution shown)
public static int c...

View Answer

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions

Unlock this Answer For Free Now!

View this answer and more for free by performing one of the following actions

qr-code

Scan the QR code to install the App and get 2 free unlocks

upload documents

Unlock quizzes for free by uploading documents