Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Recursion{
- public static void main(String[] args)
- {
- try { System.out.println(" Please input the base you would like to convert into " );
- Scanner BaseIn = new Scanner (System.in);
- int base1 = BaseIn.nextInt();
- System.out.println( "Now input the number you would like to convert" );
- Scanner NumIn = new Scanner (System.in);
- int number = NumIn.nextInt();
- BaseConversion (number, base1);
- }
- catch (Exception e)
- {
- System.out.print("somethigng stupid");
- }
- }
- public String BaseConversion(int num, int base)
- {
- if (num < base)
- {
- return new String ("" + num);
- }
- else
- {
- return BaseConversion (num/base, base) + new String("" + (num % base));
- }
- }
- }
- java Recursion
- `new Recursion().baseConversion(number, base1)` //I have changed name according to java conventions.
- public class Recursion {
- public static void main(String[] args) {
- try {
- System.out
- .println(" Please input the base you would like to convert into ");
- Scanner BaseIn = new Scanner(System.in);
- int base1 = BaseIn.nextInt();
- System.out
- .println("Now input the number you would like to convert");
- Scanner NumIn = new Scanner(System.in);
- int number = NumIn.nextInt();
- System.out.println(new Recursion().baseConversion(number, base1));
- }
- catch (Exception e) {
- System.out.print("somethigng stupid");
- }
- }
- public String baseConversion(int num, int base) {
- if (num < base) {
- return new String("" + num);
- } else {
- return baseConversion(num / base, base)
- + new String("" + (num % base));
- }
- }
- }
Add Comment
Please, Sign In to add comment