Answered step by step
Verified Expert Solution
Link Copied!

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.

CS141 Java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions

Question

Differentiate between hard and soft measures of service quality.

Answered: 1 week ago

Question

Be familiar with the different perspectives of service quality.

Answered: 1 week ago

Question

Describe key customer feedback collection tools.

Answered: 1 week ago