Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.io.File;
- import java.io.FileNotFoundException;
- public class piDigitSum{
- public static void main(String[] args){
- try{
- File source = new File("/Users/Richard/Desktop/50000PiDecimals.txt");
- Scanner input = new Scanner(source);
- String readIn = input.next();
- int sum = 0;
- for(int i=0; i<= 31415; i++){
- if(Character.getNumericValue(readIn.charAt(i)) %2 == 1){
- sum += Character.getNumericValue(readIn.charAt(i));
- }
- }
- System.out.println(Integer.toBinaryString(sum));
- }
- catch(FileNotFoundException e){
- System.out.println("The File was not found");
- }
- }
- }
- OUTPUT:
- >>10011001101001001
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement