Ask Question
14 January, 06:47

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

+4
Answers (1)
  1. 14 January, 07:13
    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 & 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