Skip to Content

List Even Numbers Java Example

  1. /*
  2.         List Even Numbers Java Example
  3.         This List Even Numbers Java Example shows how to find and list even
  4.         numbers between 1 and any given number.
  5. */
  6.  
  7. public class ListEvenNumbers {
  8.  
  9.         public static void main(String[] args) {
  10.                
  11.                 //define limit
  12.                 int limit = 50;
  13.                
  14.                 System.out.println("Printing Even numbers between 1 and " + limit);
  15.                
  16.                 for(int i=1; i <= limit; i++){
  17.                        
  18.                         // if the number is divisible by 2 then it is even
  19.                         if( i % 2 == 0){
  20.                                 System.out.print(i + " ");
  21.                         }
  22.                 }
  23.         }
  24. }
  25.  
  26. /*
  27. Output of List Even Numbers Java Example would be
  28. Printing Even numbers between 1 and 50
  29. 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
  30. */