Ask Question
Today, 11:42

Given positive integer numInsects, write a while loop that prints that number doubled without reaching 100. Follow each number with a space. After the loop, print a newline. Ex: If numInsects = 8, print:

8 16 32 64

import java. util. Scanner;

public class InsectGrowth {

public static void main (String [] args) {

int numInsects = 0;

+1
Answers (1)
  1. Today, 13:54
    0
    import java. util. Scanner;

    public class InsectGrowth {

    public static void main (String [] args) {

    int numInsects = 8;

    while (numInsects < 100) {

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

    numInsects = numInsects * 2;

    }

    System. out. println ();

    }

    }

    Explanation:

    Create the main function and define the variable numInsects with value 8.

    Take the while loop and it run until numInsects less than 100.

    Inside the loop. first print the value and less double the numInsects value.

    for example:

    suppose, numInsects = 2

    the, check condition 2 < 100, true

    print (2)

    numInsects = 2 * 2=4

    second time, numInsects = 4

    the, check condition 4 < 100, true

    print (4)

    numInsects = 4 * 2=8

    and so on, until numInsects < 100.

    Print each number with space and finally when the loop is terminate print the new line.
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 100. Follow each number with a ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers