Respuesta :
Answer:
numInsects = 16
while numInsects < 200:
print(str(numInsects) + " ", end="")
numInsects *= 2
Explanation:
*The code is in Python.
Set the numInsects as 16
Create a while loop that iterates while numInsects is smaller than 200. Inside the loop, print the value of numInsects followed by a space. Then, multiply the numInsects by 2.
Answer:
import java.util.Scanner;
public class InsectGrowth {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
int numInsects;
numInsects = scnr.nextInt(); // Must be >= 1
/* Solution starts here */
while (numInsects < 200) {
System.out.print(numInsects + " ");
numInsects = numInsects * 2;
}
System.out.println("");
/* End of solution */
}
}
Explanation:
while (numInsects < 200) { : While the input is less than 200. Begins the loop
System.out.print(numInsects + " "); : Prints number under 200 and adds a space
numInsects = numInsects * 2; : Avoids an infinite loop but changing the value before exiting while-loop. Doubles the number and then goes through loop again until it reaches 200.
} : Always make sure to end with }
System.out.println(""); : Asks to add a newline, so this adds that
(All checked on a Java compiler and Zybooks, so it should produce the correct result)