BlueJ Program on Sum of The Series s=x^2 - x^4/3! + x^6/5!-.... n terms.
import
java.util.*;
public
class Series
{
Scanner sc=new Scanner(System.in);
int s=0,n,i,j,x,c=1;
public void firstSeries()
{
System.out.print("\nEnter the
value of 'n':");
n=sc.nextInt();
System.out.print("\nEnter the
value of 'x':");
x=sc.nextInt();
for(i=2;i<=n;i=i+2)
{
s=s+(int)(Math.pow(x,i)*c/fact(i-1));
c=c*-1;
}
System.out.print("Sum of the
series x^2 - x^4/3! + x^6/5!-.... n term:"+s);
}
private int fact(int n)
{
int f=1;
for(j=1;j<=n;j++)
{
f=f*j;
}
return f;
}
public static void main(String
args[])
{
Series obj=new Series ();
obj.firstSeries();
}
}
Back To BlueJ Series Display Programs Home Page: CLICK HERE
No comments:
Post a Comment