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

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.