# javaprograms

k.jahangir kumar
javaprograms
2 Answer(s)      6 years and a month ago
Posted in : Java Beginners

compute the following series

s=5+55+555+5555+.........n terms

October 18, 2011 at 11:44 AM

```import java.util.*;
class Series
{
public static void main(String[] args)
{
//It is a geometric series. Use the formula to din the sum of n terms in Geometric Progression.
Scanner input=new Scanner(System.in);
System.out.print("Enter the value of n: ");
int n=input.nextInt();
int a=5,r=11;
double p=Math.pow(r,n);
double p1=2*(1-p);
double p2=1-r;
double sum=p1/p2;
System.out.println("Sum of series: "+sum);
}
}
```

October 18, 2011 at 11:56 AM

Check this:

```import java.util.*;
class Series
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter the value of n: ");
int n=input.nextInt();
/*
5+55+555+5555+....n
5(1+11+111+1111)
5(1+(1+10)+(1+100)+(1+1000))
5(1+1+1+1+(10+100+1000))
5(4+sum of series);
a=10,r=10
*/

int a=10,r=10;
double p=Math.pow(r,n);
double p1=10*(1-p);
double p2=1-r;
double sum=p1/p2;
double result=5*(4+sum);
System.out.println("Sum of series: "+sum);
}
}
```