UVA10931




Sample Input

1
2
10
21
0

Sample Output

The parity of 1 is 1 (mod 2).
The parity of 10 is 1 (mod 2).
The parity of 1010 is 2 (mod 2).
The parity of 10101 is 3 (mod 2).


大意:給N個數字 問每個數字轉成二進制後有幾個進位


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class UVA10931 {

 public static void main(String[] args) {
        // TODO Auto-generated method stub
 BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

  while(true){

  int num = 0;

  try {
   num = Integer.parseInt(in.readLine());
  } 
  catch (NumberFormatException | IOException e) {
   e.printStackTrace();
  }

  if(num==0)break;

  String temp = Integer.toBinaryString(num);

  int ans=0;

  for(int i=0;i<temp.length();i++)
   if(temp.charAt(i)=='1')
    ans++;

  System.out.println("The parity of "+temp+" is "+ans+" (mod 2).");

  }

 }
}