Pages

Sunday 9 September 2012

UVA - 10931 - Parity

import java.io.*;
import java.util.IllegalFormatException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

public class Main{

    public static void main(String[] args) throws FileNotFoundException {
        TextIO.readStream(System.in);
       while(true){
            int num=TextIO.getInt();
            if(num==0)
                break;
            String temp=Integer.toBinaryString(num);
            int length=Integer.bitCount(num);
            System.out.println("The parity of "+temp+" is "+length+" (mod 2).");
       
   }
}
}

No comments:

Post a Comment