May 3, 2022

Java Program To Print Odd Number | Value Enter By User

code box with copy button

Java Code



        import java.util.Scanner;

        public class oddNumber {
            public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
        
                int from;
                int to;
                System.out.println("Enter Number For Start Printing Odd ");
                from = sc.nextInt();
                System.out.println("Enter Number For Ending Printing Odd ");
                to = sc.nextInt();
                for (int i = from; i <= to; i++) {
                    if (i % 2 != 0) {
                        System.out.print(i + "\n");
                    }
                }
            }
        }
        
        

    

 

Output 

Enter Number For Start Printing Odd 

1

Enter Number For Ending Printing Odd 

10

1

3

5

7

9

Share:

0 Comments: