import java.util.*;
class SumNEvenCubes{
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*i);
}
System.out.println("sum of "+n+"cubes Even numbers: "+sum);
}}
OUTPUT:
enter number
5
sum of 5cubes Even numbers: 72
class SumNEvenCubes{
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*i);
}
System.out.println("sum of "+n+"cubes Even numbers: "+sum);
}}
OUTPUT:
enter number
5
sum of 5cubes Even numbers: 72
No comments:
Post a Comment