fork download
  1. import java.io.*;
  2.  
  3.  
  4.  
  5. class Ideone
  6. {
  7.  
  8.  
  9. public static String result;
  10. public static void main(String s[]) throws IOException
  11.  
  12. {
  13.  
  14. System.out.println("\nenter the input Number\n");
  15. String input=br.readLine();
  16.  
  17. combination("",input);
  18.  
  19.  
  20.  
  21. }
  22. public static void combination(String result, String input)
  23. {
  24. StringBuilder result1 = new StringBuilder(result);
  25. StringBuilder result2 = new StringBuilder(result);
  26. if("".equalsIgnoreCase(input))
  27. {
  28. System.out.println( result);
  29. return; }
  30. if(input.length() >= 1)
  31. {
  32. int singleNum = Integer.parseInt(input.substring(0, 1));
  33. result1.append(translate(input.substring(0, 1)));
  34. combination(result1.toString(), input.substring(1));
  35. }
  36. if(input.length() >= 2)
  37. {
  38. int doubleNum = Integer.parseInt(input.substring(0, 2));
  39. if (doubleNum <= 26)
  40. {
  41. result2.append(translate(input.substring(0, 2)));
  42. combination(result2.toString(), input.substring(2));
  43. }
  44. }
  45. }
  46.  
  47.  
  48.  
  49.  
  50. public static char translate(String a)
  51. {
  52. switch(a)
  53. {
  54. case "1" :
  55. return 'a';
  56. case "2" :
  57. return 'b';
  58. case "3" :
  59. return 'c';
  60. case "4":
  61. return 'd';
  62. case "5":
  63. return 'e';
  64. case "6":
  65. return 'f';
  66. case "7":
  67. return 'g';
  68. case "8":
  69. return 'h';
  70. case "9":
  71. return 'i';
  72. case "10":
  73. return 'j';
  74. case "11" :
  75. return 'k';
  76. case "12":
  77. return 'l';
  78. case "13":
  79. return 'm';
  80. case "14":
  81. return 'n';
  82. case "15":
  83. return 'o';
  84. case "16":
  85. return 'p';
  86. case "17":
  87. return 'q';
  88. case "18":
  89. return 'r';
  90. case "19":
  91. return 's';
  92. case "20":
  93. return 't';
  94. case "21":
  95. return 'u';
  96. case "22":
  97. return 'v';
  98. case "23":
  99. return 'w';
  100. case "24":
  101. return 'x';
  102. case "25":
  103. return 'y';
  104. case "26":
  105. return 'z';
  106. default :
  107. return '0';
  108.  
  109. }
  110.  
  111. }
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119. }
Success #stdin #stdout 0.11s 320512KB
stdin
12258
stdout
enter the input Number

abbeh
abyh
aveh
lbeh
lyh