This is a series program using BlueJ. Here 2,4,8 are 21, 22, 23
Write this program using
n: stores the number of terms
s: double type variable to store sum of
series
Exponent value is 2
import java.util.*;
class Search
{
long n;
double s;
Scanner sc=new Scanner(System.in);
public void assign()
{
System.out.print("\nEnter the values of
'n':");
n=sc.nextLong();
}
public void display()
{
for(long i=1;i< =n;i++)
{
s=s+Math.pow(2,i)/fact(i);
}
System.out.print("\nSum of the series = " + s);
}
public long fact(long x)
{
long f=1;
for(long i=1;i< =x;i++)
f=f*i;
return f;
}
public static void main(String args[])
{
Search ob=new Search();
ob.assign();
ob.display();
}
}
Back To BlueJ Series Display Programs Home Page: CLICK HERE
No comments:
Post a Comment