Odd Number Between 1-99 Using For Loop in Java

thumbnail

Today I’ll share java code to display a list of an odd number between 1-99 using for loop in java. The idea in this post is I want to display odd numbers of 1 3 5 7 9 until number 99. However, I want to display all the odd numbers from 1 – 99 with 9 rows and 5 columns. Here the code how you can implement that case.

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

From the code above, you will see the output below.

1 3 5 7 9
11 13 15 17 19
21 23 25 27 29
31 33 35 37 39
41 43 45 47 49
51 53 55 57 59
61 63 65 67 69
71 73 75 77 79
81 83 85 87 89
91 93 95 97 99

You can see this project file at my Github.

Back To Top