can anyone help with this Java program...pls
Attachments:
Answers
Answered by
0
Answer:
import java.util.*;
class series
{
public void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the limit");
int n=sc.nextInt();
double S=0.0;
int p=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
p=p*j;
}
S=S+(1.0/p);
}
System.out.println("Sum="+S);
}
}
Explanation:
We have to start with the factorial of the number .
Run two loops and the inner loop should calculate the factorial .
If we do not keep the datatype of S in double , the printing will be 0 always .
Implicit typecasting will take place from int to double .
Similar questions
English,
6 months ago
English,
6 months ago
Math,
11 months ago
Political Science,
11 months ago
Physics,
1 year ago