public class HelloJava {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Hello Java!");
}
}
package funtion;
public class FunctionJava {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println(" <
A a = new A();
System.out.println("faci(5) = " + a.faci(5));
System.out.println("facr(5) = " + a.facr(5));
//System.out.println("faci(50) = " + a.faci(50));
}
}
class A{
long faci(int n){
long result=1;
for(int i=2;i<=n;i++){
result*=i;
}
return result;
}
long facr(int n){
if(n<1){
return 1;
}
return facr(n-1)*n;
}
}
沒有留言:
張貼留言