Respuesta :
Complete Question:
Write code that prints: Ready! userNum ... 2 1 Blastoff! Your code should contain a for loop. Print a newline after each number and after each line of text Ex: userNum = 3 outputs: Ready! 3 2 1 Blastoff!
Answer:
public class TestClock {
public static void main(String[] args) {
int userNum= 3;
System.out.print("Ready! "+userNum+" ");
for (int i=userNum;i>1; i--){
userNum--;
System.out.print(userNum+" ");
}
System.out.println("Blasoff!");
}
}
Explanation:
- Create and initialize userNum
- Use System.out.print to print the sequence ("Ready! "+userNum+" ") on same line
- use for statement with this condition for (int i=userNum;i>1; i--) decremeent userNum by 1 after each loop iteration and print userNum on same line
- outside the for loop print "Blasoff!"
The code is in Python.
It uses for loop to print the required output. Please be aware that we handle the parts that needs to be repeated inside the loop, i.e. printing the number and decreasing it. However, printing "Ready!" and "Run!" are handled before and after the loop respectively.
Comments are used to explain each line of code
#Initializing the variable
firstNumber = 5
#Printing Ready!
print("Ready!")
#for loop that iterates firstNumber of times
#Inside the loop, print the firstNumber, then decrease the firstNumber by 1
for i in range(firstNumber):
print(firstNumber)
firstNumber-=1
#Printing Run!
print("Run!")
You may read more about the loops in the following link:
brainly.com/question/14577420