fork download
  1. import java.util.Scanner;
  2.  
  3. class Main
  4. {
  5. private static final char[] CODE_TABLE = {'0','1','2','3','4','5','6','7','8','9','A'};
  6. private static final char[] CODE_TABLE_HEX = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
  7.  
  8. public static void main (String[] args) {
  9.  
  10. Scanner scanner = new Scanner(System.in);
  11. int howManyTry = scanner.nextInt();
  12. for (int i = 0; i < howManyTry; i++) {
  13.  
  14. StringBuilder stringBuilderEleven = new StringBuilder();
  15. StringBuilder stringBuilderHex = new StringBuilder();
  16. int decValue = scanner.nextInt();
  17. eleven(decValue, stringBuilderEleven);
  18. hexa(decValue, stringBuilderHex);
  19. System.out.print(stringBuilderHex.reverse());
  20. System.out.print(" ");
  21. System.out.print(stringBuilderEleven.reverse());
  22. System.out.println();
  23. }
  24. }
  25. public static void eleven(int decValue, StringBuilder aa){
  26.  
  27. int modulo;
  28. if(decValue<=10){
  29. aa.append(CODE_TABLE[decValue]);
  30. }
  31. else{
  32.  
  33. modulo=decValue%11;
  34. aa.append(CODE_TABLE[modulo]);
  35. decValue=(decValue-modulo)/11;
  36. eleven(decValue, aa);
  37.  
  38. }
  39.  
  40. }
  41. public static void hexa(int decValue, StringBuilder aa){
  42.  
  43. int modulo;
  44. if(decValue<=16){
  45. aa.append(CODE_TABLE_HEX[decValue]);
  46. }
  47. else{
  48.  
  49. modulo=decValue%16;
  50. aa.append(CODE_TABLE_HEX[modulo]);
  51. decValue=(decValue-modulo)/16;
  52. hexa(decValue, aa);
  53.  
  54. }
  55.  
  56. }
  57.  
  58. }
Success #stdin #stdout 0.14s 56628KB
stdin
2
1263
10
stdout
4EF A49
A A