UVA 10019 Java

  1. import java.util.*;
  2. import static java.lang.System.*;
  3. public class main{
  4. public static void main(String[] args) {
  5. Scanner sc=new Scanner(System.in);
  6. int lines = sc.nextInt();
  7. for(int i =0; i < lines; i++)
  8. {
  9. String input = Integer.toString(sc.nextInt());
  10. String bin_str = Integer.toBinaryString(Integer.parseInt(input));
  11. int count1 = 0;
  12. for(int j = 0; j < bin_str.length(); j++)
  13. if(bin_str.charAt(j) == '1')
  14. count1 ++;
  15. String hex_to_dec_str = Integer.toBinaryString(Integer.parseInt(input, 16));
  16. int count2 = 0;
  17. for(int j = 0; j < hex_to_dec_str.length(); j++)
  18. if(hex_to_dec_str.charAt(j) == '1')
  19. count2 ++;
  20. System.out.println(String.format("%d %d", count1, count2));
  21. }
  22. }
  23. };
  24.  

留言

這個網誌中的熱門文章

C# 井字遊戲