Write a method highLow that accepts an integer as a parameter and returns whethe
ID: 660791 • Letter: W
Question
Write a method highLow that accepts an integer as a parameter and returns whether or not the number has alternating "high" and "low" digits. 0 through 4 are "low" digits and 5 through 9 are "high" digits. Your method should return true if the number passed alternates between "high" and "low" digits, and false if not. You may assume the number passed is positive. If the number passed consists of a single digit, your method should return true.
Note: The method returns true if the number alternates starting with a "high" digit or starting with a "low" digit. What is important is that the digits alternate. For example, both highLow(9292) and highLow(2929) should return true.
Here are some example calls to the method and their resulting return values:
You may not use a String to solve this problem.
Method problem: For this problem, you are supposed to write a Java method as described. You should notwrite a complete Java class; just write the method(s) described in the problem statement.
Call Value Returned highLow(1918193) true highLow(7283) true highLow(3827) true highLow(9388) false highLow(895151) false highLow(707) true highLow(44) false highLow(45) true highLow(5) trueExplanation / Answer
Output : true true true false false true false true true
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.