這是我的代碼。我不明白爲什麼我一直這樣做?繼續在線程「main」中得到異常java.lang.NoSuchMethodError:main?
它應該遞歸地將鹼基從十個鹼基改變到任何給定的鹼基。
任何幫助都會很棒。
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));
}
}
}
你可以添加你想要的輸出嗎?不能對非靜態方法BaseConversion(int,int)進行靜態引用。 – gks
你的代碼是如何編譯的?你永遠不應該運行一個包含編譯錯誤的代碼。 –