Question
Design a class to overload a function series() as follows:
(i) void series(int x, int n) – To display the sum of the series given below:
x¹+x²+x³+. . . . .x^n terms
(ii)void series(int p) – To display the following series
0, 7, 26, 63. . . . .p terms
(iii) void series() – To display the sum of the series given below:
1/2+1/3+1/4+. . . . . .1/10
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
public class program7
{
public void series(int x,int n)
{
int sum=0,i=0;
for(i=1;i<=n;i++)
{
sum= sum + (int)Math.pow(x,i);
}
System.out.println(sum);
}
public void series(int p)
{
int i=0;
for(i=1;i<=p;i++)
{
System.out.print((i*i*i-1)+",");
}
}
public void series()
{
double sum=0,i=0;
for(i=2;i<=10;i++)
{
sum = sum + 1/i;
}
System.out.println(sum);
}
}