Display The Even Numbers In Java

  1. import java.io.*;  
  2.   
  3. class AllEvenNum{  
  4.     public static void main(String[] args) {  
  5.         try{  
  6.             BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));  
  7.             System.out.println("Enter number : ");  
  8.             int num = Integer.parseInt(br1.readLine());  
  9.             System.out.println("Even Numbers:");  
  10.             for (int i=1;i <=num ; i++){  
  11.                 if(i%2==0 ){  
  12.                     System.out.print(i+",");  
  13.                 }  
  14.             }  
  15.         }  
  16.         catch(Exception e){}  
  17.           
  18.     }  
  19. }