Write a program to print first n even numbers in java

Write a program to print first n even numbers in java
Like Tweet Pin it Share Share Email

This program you will learn how to use both conditional and looping constructs in a nested format, that is a conditional statement would be present inside a for loop. As mentioned in other articles, there would be several ways to write logic for any problem / program, here I am showing some of the simple ways to solve the program.

Way 1 – using a “for” loop

Way 2 – using a “while” loop

There are more ways, by creating a class and methods which can be called, the above program is also a way of writing a class writing the logic in a main method, but the predefined main method cannot be called by other classes. You may have to give a different method declaration other than the default main method provided by java. You will learn this in the tutorials which talks about creating classes and methods in java.

Please feel free to share your queries in form of comments, we would be more than happy to respond.

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *