102k views
1 vote
Write code that prints: Ready! userNum ... 2 1 Go! Your code should contain a for loop. Print a newline after each number and after each line of text. Ex: If the input is: 3 the output is: Ready! 3 2 1 Go!

User Grokpot
by
4.7k points

1 Answer

1 vote

Answer:

Kindly find the code snippet in the explanation written in kotlin language

Step-by-step explanation:

fun main(args: Array<String>) {

var num:Int

println("Enter a num")

num= Integer.valueOf(readLine())

for(i in num downTo 1){

if(i==num){

print("Ready!")

print(" ")

}

print(i)

print(" ")

if(i==1){

print(" ")

print("Go!")

}

}

}

This function too can also work

fun numTo(num:Int){

if (num>0) for(i in num downTo 1) print("$i ")

println("Go!")

User Armen
by
4.0k points