我是剛開學JAVA,想請教一個問題。

jiaosir發表於2005-08-10
Exception in thread "main" java.lang.NoSuchMethodError: main

我在執行一個小程式時提示我這個,我不知是那點出了問題,編譯時是沒有報錯的,那位能幫我,小弟先謝謝了。程式碼如下:


import java.io.*;
import java.lang.*;
import java.awt.*;
public class test{
public static int factorial(int num){
if(num>0)
if(num==1) return 1;
else return(num*factorial(num-1));
else
{System.out.println("不能為負數求階乘");
return 0;
}
}


public static void calculate(int num){
//階乘測試
System.out.println("Test of factorial recursive:");
System.out.println("\n");
System.out.println(num+"的階乘是:"+factorial(num)+"/n");
}


public static void main(String args) throws IOException{
System.out.println("Please input the number that you want to calculate:");
String s;
try
{
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(ir);
s=in.readLine();
int num=Integer.parseInt(s);
calculate(5);
}
catch(IOException e)
{System.out.println(e);}
}
}

相關文章