Guest User

Untitled

a guest
Jan 22nd, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Recursion{
  4.  
  5. public static void main(String[] args)
  6. {
  7. try { System.out.println(" Please input the base you would like to convert into " );
  8. Scanner BaseIn = new Scanner (System.in);
  9. int base1 = BaseIn.nextInt();
  10.  
  11. System.out.println( "Now input the number you would like to convert" );
  12. Scanner NumIn = new Scanner (System.in);
  13. int number = NumIn.nextInt();
  14.  
  15. BaseConversion (number, base1);
  16. }
  17.  
  18. catch (Exception e)
  19. {
  20. System.out.print("somethigng stupid");
  21. }
  22. }
  23.  
  24. public String BaseConversion(int num, int base)
  25. {
  26. if (num < base)
  27. {
  28. return new String ("" + num);
  29. }
  30. else
  31. {
  32. return BaseConversion (num/base, base) + new String("" + (num % base));
  33. }
  34. }
  35.  
  36. }
  37.  
  38. java Recursion
  39.  
  40. `new Recursion().baseConversion(number, base1)` //I have changed name according to java conventions.
  41.  
  42. public class Recursion {
  43.  
  44. public static void main(String[] args) {
  45. try {
  46. System.out
  47. .println(" Please input the base you would like to convert into ");
  48. Scanner BaseIn = new Scanner(System.in);
  49. int base1 = BaseIn.nextInt();
  50.  
  51. System.out
  52. .println("Now input the number you would like to convert");
  53. Scanner NumIn = new Scanner(System.in);
  54. int number = NumIn.nextInt();
  55.  
  56. System.out.println(new Recursion().baseConversion(number, base1));
  57. }
  58.  
  59. catch (Exception e) {
  60. System.out.print("somethigng stupid");
  61. }
  62. }
  63.  
  64. public String baseConversion(int num, int base) {
  65. if (num < base) {
  66. return new String("" + num);
  67. } else {
  68. return baseConversion(num / base, base)
  69. + new String("" + (num % base));
  70. }
  71. }
  72.  
  73. }
Add Comment
Please, Sign In to add comment