A Java Program for solving the power series 1+1/2^2+...+1/n^2.
import java.io.*; class Series2 { public static void main(String args[]) throws IOException { int n; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter n value: "); n = Integer.parseInt(br.readLine()); if(n>0) { float sum=0; for(int i=1; i<=n; i++) sum=sum+(float)(1)/(i*i); System.out.println("Sum of Series:"+sum); } else System.out.println("You Entered the Wrong no."); } }
OUTPUT:
Enter n value 16 Sum of Series:1.5843465