Ask Question
16 September, 20:35

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

+1
Answers (1)
  1. 16 September, 22:33
    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?
Find 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 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