Menu

Read a number from the user and Display sum of first n even numbers

import java.util.*;
class Sum_of_n_even_numbers{
public static void main(String args[]){

System.out.print("How many even numbers you want to add ?");
Scanner sc= new Scanner(System.in);
int n = sc.nextInt();
int sum=0;
int count=0;
if(n>=1)
{

for(int i=1; i<=1000000;i++)
{

if(i%2==0)
{sum=sum+i; count++;}
if(count==n) break;
}

}

System.out.println("The sum of first "+n+" even numbers is "+sum);
System.out.println(count);

}}