import java.util.*;
class SumNSquare{
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int sum=0;
System.out.println("enter number");
int n=scan.nextInt();
for(int i=0;i<=n;i++)
{
if(i%2==0)
sum=sum+(i*i);
}
System.out.println("sum of "+n+"Square even numbers: "+sum);
}}
OUTPUT:
enter number
5
sum of 5Square even numbers: 20
class SumNSquare{
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int sum=0;
System.out.println("enter number");
int n=scan.nextInt();
for(int i=0;i<=n;i++)
{
if(i%2==0)
sum=sum+(i*i);
}
System.out.println("sum of "+n+"Square even numbers: "+sum);
}}
OUTPUT:
enter number
5
sum of 5Square even numbers: 20
No comments:
Post a Comment