Kotlin Program to print first n odd numbers in descending order
In this program, You will learn how to print first n odd numbers in descending order in Kotlin.
Some list are:13 11 9 7 5 3 1
Example: How to print first n odd numbers in descending order in Kotlin.
import java.util.Scanner
fun main(args: Array<String>) {
var n: Int
var a: Int
var sc = Scanner(System.`in`)
print("Enter a number:")
n = sc.nextInt()
print("List are:")
for (i in n-1 downTo 0) {
a = 1 + i * 2
print("$a ")
}
}
Output:
Enter a number:10
List are:19 17 15 13 11 9 7 5 3 1