Write a Java program to print first 10 even natural numbers using for loop.
package NumPrograms; public class First10EvenNaturalNum1 { public static void main(String[] args) { System.out.println("The First 10 Even Natural Numbers are"); for(int i = 1; i <= 10; i++) { System.out.println(2 * i); } } }
Java Program to print the first 10 even natural numbers using a while loop.
package NumPrograms; public class First10EvenNaturalNum2 { public static void main(String[] args) { System.out.println("The First 10 Even Natural Numbers are"); int i = 1; while( i <= 10) { System.out.println(2 * i); i++; } } }
The First 10 Even Natural Numbers are
2
4
6
8
10
12
14
16
18
20
This Java example displays the first 10 even natural numbers using the do while loop.
package NumPrograms; public class First10EvenNaturalNum3 { public static void main(String[] args) { System.out.println("The First 10 Even Natural Numbers are"); int i = 1; do { System.out.println(2 * i); } while(++i <= 10); } }
The First 10 Even Natural Numbers are
2
4
6
8
10
12
14
16
18
20
Please refer to
- Print the First 10 Natural Numbers
- Print the First 10 Natural Numbers in Reverse
- Print the First 10 Odd Natural Numbers
- Java program to Print Even Numbers from 1 to N
- Java program to Print Odd Numbers from 1 to N
- Java program to Print Natural Numbers from 1 to N
- Java program to Print Natural Numbers in Reverse Order
- Java Program to Find the Sum of Natural Numbers from 1 to N