Saturday, August 31, 2019

Display Sum of Series: 1 + (1+2) / (1*2) + (1+2+3) / (1*2*3) + ….. + (1+2+3+…+n) / (1*2*3*…*n)

This is a BlueJ Program which displays sum of a series using nested loop.



import java.util.*;
class Max
{
Scanner sc=new Scanner(System.in);
int n,i,j;
double sum=0;
int s,p;
public void take()
{
System.out.print("\nValue of 'n': ");
n=sc.nextInt();



for(i=1;i< =n;i++)
{
    s=0;
    p=1;
  for(j=1;j< =i;j++)
  {
      s=s+j;
      p=p*j;
    }
    sum=sum + (double)s/p; 
}
System.out.println("\nSum of the series: "+sum);
}
public static void main(String args[])
{
Max ob=new Max();
ob.take();
}
}


Back To BlueJ Series Display Programs Home Page: CLICK HERE

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner