01/02/06 recursion
import javax.swing.JOptionPane;
public class recursion {
public static void main(String[] arg){
String PString=JOptionPane.showInputDialog("請輸入一非負整數:");
int i=Integer.parseInt(PString);
System.out.println(i+"! = "+recursion.orders(i));
System.exit(0);}
public static int orders(int i){
int n=1;
if (i==0){return 1;}
else if(i>0){ return(orders(i-1)*i);
}
else return 0;}
}
圖檔
0 Comments:
Post a Comment
<< Home