Java programme to print first n even numbers using while loop
import java.util.Scanner ;
public class nilesh {
public static void main (String args[]){
System.out.println("Enter the number :: ");
Scanner sc=new Scanner (System.in);
int n=sc.nextInt();
int i=0;
int sum=0;
while (i<n){
i++;
sum=sum+(2*i);
}
System.out.printf("Sum of %d even no is =%d",n,sum);}}
Comments
Post a Comment