Notice: Constant WP_MEMORY_LIMIT already defined in /home/javawith/public_html/codesjava.com/wp-config.php on line 107

Notice: Constant WP_MAX_MEMORY_LIMIT already defined in /home/javawith/public_html/codesjava.com/wp-config.php on line 108
List Even Numbers in Java - CodesJava

CodesJava

Easy learning with example program codes

List Even Numbers Java Example


Notice: Undefined variable: footnotelist in /home/javawith/public_html/codesjava.com/wp-content/plugins/latex2html/inc/core.php on line 475

 

Program to List Even Numbers in Java.

/**
 * Program to List Even Numbers Java Example.
 * @author CodesJava
 */
public class ListEvenNumberExample {
	static void listEvenNumber(int limitNumber){
		//Print limit number.
		System.out.println("Even numbers between 1 and " + limitNumber + ":");
 
		//Find even numbers.
                for(int i=1; i <= limitNumber; i++){               
                   //Test even number condition.
                   if( i % 2 == 0){
                      System.out.println(i);
                   }
              }
	}	
 
	public static void main(String args[]){ 
		//method call 
                listEvenNumber(60); 
	}
}

Output:

Even numbers between 1 and 60: 
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

 

Please follow and like us:
error
Posted in Java   

Core Java Tutorial








Copyright © 2019 CodesJava DMCA.com Protection Status