Advertisement
Guest User

Untitled

a guest
Jun 27th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. public class piDigitSum{
  5.    public static void main(String[] args){
  6.       try{
  7.          File source = new File("/Users/Richard/Desktop/50000PiDecimals.txt");
  8.          Scanner input = new Scanner(source);
  9.          String readIn = input.next();
  10.          int sum = 0;
  11.          for(int i=0; i<= 31415; i++){
  12.             if(Character.getNumericValue(readIn.charAt(i)) %2 == 1){
  13.                
  14.                sum += Character.getNumericValue(readIn.charAt(i));
  15.             }
  16.          }
  17.          System.out.println(Integer.toBinaryString(sum));
  18.       }
  19.       catch(FileNotFoundException e){
  20.          System.out.println("The File was not found");
  21.       }
  22.    }
  23. }
  24.  
  25.  
  26.  
  27.  
  28. OUTPUT:
  29.  
  30. >>10011001101001001
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement