Java Programme to print first n even numbers using for 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 sum=0; 

          int i,n=sc.nextInt(); 

          for (i=0; i<n; i++){

              sum=sum+(2*i);

          }

              System.out.printf ("Sum of %d no is =%d  ",n, sum );}}

Comments

Popular posts from this blog

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