Even Number Between 1-100 Using For Loop in Java

thumbnail

Today I’ll share java code to display a list of an even number between 1-100 using for loop in java. Similar like the odd number, the idea in this post is I want to display odd numbers of 2 4 6 8 10 until number 100. However, I want to display all the odd numbers from 1 – 100 with 9 rows and 5 columns. Here the code how you can implement that case.

public class EvenNumberLoop {

    public static void main(String[] args) {
        for (int i=1; i<=100; 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.

2 4 6 8 10
12 14 16 18 20
22 24 26 28 30
32 34 36 38 40
42 44 46 48 50
52 54 56 58 60
62 64 66 68 70
72 74 76 78 80
82 84 86 88 90
92 94 96 98 100

You can see this project file at my Github.

Back To Top