Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a method called showTwos that uses a while loop to create a string that show the factors of 2 in a given integer. For
Write a method called showTwos that uses a while loop to create a string that show the factors of 2 in a given integer. For example the following calls should return the strings seen below showTwos(7) "7 = 7" showTwos(18) "18 = 2 * 9" showTwos(68) "68 = 2 * 2 * 17" showTwos(120) "120 = 2 * 2 * 2 * 15" showTwos(192) "192 = 2 * 2 * 2 * 2 * 2 * 2 * 3" showTwos(8) "8 = 2 * 2 * 2 * 1" OR (either version is fine) "8 = 2 * 2 * 2" You may choose to make the function just a void function that prints it out, or for a stronger case, you may have the method build a string and return the string to be printed out by the main program. could anybody solve this question? clear words and answer please
Write a method called showTwos that uses a while loop to create a string that show the factors of 2 in a given integer. For example the following calls should return the strings seen below
showTwos(7)
"7 = 7"
showTwos(18)
"18 = 2 * 9"
showTwos(68)
"68 = 2 * 2 * 17"
showTwos(120)
"120 = 2 * 2 * 2 * 15"
showTwos(192)
"192 = 2 * 2 * 2 * 2 * 2 * 2 * 3"
showTwos(8)
"8 = 2 * 2 * 2 * 1"
OR (either version is fine)
"8 = 2 * 2 * 2"
You may choose to make the function just a void function that prints it out, or for a stronger case, you may have the method build a string and return the string to be printed out by the main program.
could anybody solve this question?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started