Java 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 java.
List of odd numbers in descending order : 11, 9 , 7, 5, 3, 1
Example: How to print first n odd numbers in descending order in java.
import java.util.Scanner;
class Main {
public static void main(String args[]) {
int i, n, a;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number:");
n = sc.nextInt();
System.out.println("Odd number in descending order:");
for (i = n - 1; i >= 0; i--) {
a = 1 + i * 2;
System.out.println(a);
}
}
}
Output:
Enter a number:10
Odd number in descending order:
19
17
15
13
11
9
7
5
3
1