Examlex

Solved

Programming
Write a Static Method Named ConsecutiveDigits That Accepts an Integer

question 6

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}


Definitions:

Decisions

The results of decision-making processes, often leading to a specific action or strategy.

Dominating Influence

The overpowering impact or control one entity has over others in its environment.

Authority

The power or right to give orders, make decisions, and enforce obedience, often within a specific context such as an organization or institution.

Influence

The power to affect or change behavior, opinions, or the course of events through direct actions or persuasions.

Related Questions