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

Popular posts from this blog

Create an array of 5 floats and calculate their sum in java .