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:

Instrument Analysis

The use of instruments to measure and analyze the physical and chemical properties of substances.

TNT

Trinitrotoluene, an explosive compound used in munitions and as a reference for measuring explosives' strength.

Walk-through Detector

A type of security device designed to detect metal objects, such as weapons or contraband, on individuals as they pass through the detection framework.

Airport Explosive

A term referring to explosive materials or devices detected or mitigated in airport security measures.

Related Questions