Sum of Series Programs
//S = 1 + 2 + 3 + 4 + 5 + . . . + n
import java.util.*;
class SumOfSeries
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int a=1, n ,s = 0;
System.out.print("Enter the Last Limit ; ");
n=sc.nextInt();
while(a<=n)
{
s = s + a;
a = a + 1;
}
System.out.println("The Sum of Series is "+s);
}
}
//S = 1/12 + 1/22 + 1/32 + 1/42 + 1/52 + . . . +1/ n2
import java.util.*;
class SumOfSeries1
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int a=1, n;
float s=0.0f;
System.out.print("Enter the Last Limit ; ");
n=sc.nextInt();
while(a<=n)
{
s = s + (1/(a*a));
a = a + 1;
}
System.out.println("The Sum of Series is "+s);
}
}