using java
LO: (Analyze) Students will fix a loop that runs forever.
This program runs the countdown sequence for a rocket launch.
However, it seems to loop infinitely. Fix the program so it counts
down and terminates properly.
starter code :
import java.util.Scanner;
/*
* Counts down to a blastoff, starting from a given number.
*/
public class Countdown {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
int countdown = 0;
countdown = sc.nextInt();
while (countdown != 0) {
System.out.println(countdown + "...");
countdown--;
}
System.out.println("Blast
off!");
System.exit(0);
}
}
import java.util.Scanner; /* * Counts down to a blastoff, starting from a given number. */ public class Countdown { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int countdown = 0; countdown = sc.nextInt(); while (countdown > 0) { System.out.println(countdown + "..."); countdown--; } System.out.println("Blast off!"); System.exit(0); } }
Get Answers For Free
Most questions answered within 1 hours.