Write a program to print odd from n to 1
You will get an integer input n, and you have to print all the odd numbers from n to 1 such that each number should be printed in a separate line.
Input Format
For each test case, you will get an integer input n.
Constraints
1<=n<=2^31-1
Output Format
You have to print all the odd numbers in an integer format from n to 1.
Sample Input 0
30
Sample Output 0
29
27
25
23
21
19
17
15
13
11
9
7
5
3
1
Sample Input 1
20
Sample Output 1
19
17
15
13
11
9
7
5
3
1
Sample Input 2
25
Sample Output 2
25
23
21
19
17
15
13
11
9
7
5
3
1
Sample Input 3
7
Sample Output 3
7
5
3
1
Sample Input 4
11
Sample Output 4
11
9
7
5
3
1
Also read: Print numbers from n to 3 using a while loop
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int i=n;
while(i>=1){
if(i%2!=0){
System.out.println(i);
}
i--;
}
}
}