UVA 10641 Java

  1. import java.util.*;
  2. import static java.lang.System.*;
  3.  
  4. public class main{
  5. public static void main(String[] args) {
  6. Scanner sc=new Scanner(System.in);
  7. while(sc.hasNextInt())
  8. {
  9. int n = sc.nextInt();
  10. if(n == 0)
  11. break;
  12. String str = Integer.toBinaryString(n);
  13. int count = 0;
  14. for(int i = 0; i < str.length(); i++)
  15. if(str.charAt(i) == '1')
  16. count++;
  17. System.out.printf("The parity of %s is %d (mod 2).\r\n", str, count);
  18. }
  19. }
  20. };
  21.  

留言

這個網誌中的熱門文章

C# 井字遊戲