星期三, 1月 04, 2006

Lab 1-02-2006 Recursion

import javax.swing.JOptionPane;
public class Recursion
{
public static void main(String[] arg)
{
String PString=JOptionPane.showInputDialog("Please enter a number n=");
int i=Integer.parseInt(PString);
System.out.println( +i+"! is "+Recursion.com(i));
System.exit(0);
}
public static int com(int i)
{
int n=1;
if (i==0)
{
return 1;
}
else if(i>0)
{
return(com(i-1)*i);
}
else return 0;
}
}

0 Comments:

張貼留言

<< Home