UVA 10641 Java
- import java.util.*;
- import static java.lang.System.*;
- public class main{
- public static void main(String[] args) {
- Scanner sc=new Scanner(System.in);
- while(sc.hasNextInt())
- {
- int n = sc.nextInt();
- if(n == 0)
- break;
- String str = Integer.toBinaryString(n);
- int count = 0;
- for(int i = 0; i < str.length(); i++)
- if(str.charAt(i) == '1')
- count++;
- System.out.printf("The parity of %s is %d (mod 2).\r\n", str, count);
- }
- }
- };
留言
張貼留言