Question: 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
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
