Print Even Numbers up to N in Java . Java Practice Interview Programs

Print Even Numbers up to N in Java . Java Practice Interview Programs

Print Even Numbers up to N in Java . Java Practice Interview Programs


1). Print Even Numbers up to 100 in java.

 public class evennumber {  
   public static void main(String[] args) {  
     int n=100;   
     for (int i=1;i<=100;i++){  
       if (i%2==0){  
         System.out.println(i);  
       }  
     }  
   }  
 }  

 2).Print Even Numbers up to N By Taking User Input in java.

 import java.util.Scanner;  
 public class evennum {  
   public static void main(String[] args) {  
     Scanner sc=new Scanner(System.in);  
     System.out.println("Enter up to How many Number You want Even Number?");  
     int n=sc.nextInt();  
     for (int i=1;i<=n;i++){  
       if (i%2==0){  
         System.out.println(i);  
       }  
     }  
   }  
   }  



Post a Comment

0 Comments