Ask Question
4 January, 19:27

Given positive integer num_insects, write a while loop that prints that number doubled up to, but without exceeding 100. Follow each number with a space. Sample output with input: 8 8 16 32 64

+2
Answers (1)
  1. 4 January, 22:37
    0
    import java. util. Scanner;

    public class CocaColaVendingTest {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("Enter value for number of insects");

    int num_insects = in. nextInt ();

    while (num_insects<=100) {

    System. out. print (num_insects);

    num_insects*=2;

    System. out. print (" ");

    }

    }

    }

    Explanation:

    In the code above written in Java.

    The user is prompted to enter a positive value for the number of insects

    This is stored in a variable num_insects.

    Using a while loop with the condition while (num_insects<=100). The num_insects is printed out. Then it is doubled followed with a space.

    It continues until the condition in the while loop is no longer true
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Given positive integer num_insects, write a while loop that prints that number doubled up to, but without exceeding 100. Follow each number ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers