Shavit

Ex. Bank #20

Dec 6th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.45 KB | None | 0 0
  1. // Shavit Borisov
  2. // HW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class PiCalculation {
  7.  
  8.     public static void main(String[] args)
  9.    
  10.     {
  11.         Scanner in = new Scanner (System.in);
  12.        
  13.         int input;
  14.         double pi = 0;
  15.        
  16.         System.out.print("Enter a nubmer: ");
  17.         input = in.nextInt();
  18.        
  19.         for(int i = 1; i <= input; i++)
  20.         {
  21.             pi += 1 / (Math.pow(i, 2));
  22.         }
  23.        
  24.         pi = Math.sqrt(6*pi);
  25.         System.out.printf("Pi = %f", pi);
  26.        
  27.         in.close();
  28.     }
  29.    
  30. }
Add Comment
Please, Sign In to add comment