write a program in java and display the sum of the following series s=a^2+a^2/2+a^2/3+.............. +a^2/10
Answers
Answered by
7
Question:-
Write a program in java to find the sum of the following series.
S=a²/1+a²/2+....+a²/10
Program:-
import java.util.*;
class Sum
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the value of a: ");
int a=sc.nextInt();
if(a==0)
System.out.println("Result is: 0");
else
{
double s=0;
for(double i=1;i<=10;i++)
{
s+=Math.pow(a, 2)/i;
}
System.out.println("Result is: "+s);
}
}
}
Similar questions