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 Odd numbers: "+sum);
}}
OUTPUT:
enter number
5
sum of 5Square Odd numbers: 35
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 Odd numbers: "+sum);
}}
OUTPUT:
enter number
5
sum of 5Square Odd numbers: 35
No comments:
Post a Comment