Ask Question

Given positive integer numInsects, write a while loop that prints that number doubled without reaching 200. Follow each number with a space. After the loop, print a newline. Ex: If numInsects = 16, print:16 32 64 128 import java. util. Scanner; public class InsectGrowth {public static void main (String [] args) {int numInsects; Scanner scnr = new Scanner (System. in); numInsects = scnr. nextInt (); / / Must be > = 1 / * Your solution goes here * / }}

+3
Answers (1)
  1. 11 June, 14:36
    0
    The below code is pasted in the place of "/*Your solution goes here * / "

    while (numInsects<200) / / while loop

    {

    System. out. print (numInsects+" "); / / print statement

    numInsects=numInsects*2; / / operation to print double.

    }

    Output:

    If the user gives inputs 16 then the output is 16 32 64 128. If the user gives inputs 25 then the output is 25 50 100.

    Explanation:

    The above code is in java language in which the code is pasted on the place of "Your solution" in the question then only it can work. Then the program takes an input from the user and prints the double until the value of double is not 200 or greater than 200. In the program, there is while loop which checks the value, that it is less than 200 or not. If the value is less the operation is performed otherwise it terminates.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Given positive integer numInsects, write a while loop that prints that number doubled without reaching 200. Follow each number with a ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers