Java Code To Print Odd Numbers In A Range From 1 To 100.

 This code prints the odd numbers in a given range. 

code box with copy button

Java Code



        public class oddNumber {
            public static void main(String[] args) {
                int from = 1;
                int to = 10;
        
                for(int i = from; i <= to; i++) {
                    if(i % 2 != 0) {
                        System.out.print(i + "\n");
                    }
                }
            }
        }
        

    


Output 

1

3

5

7

9


Post a Comment

0 Comments