재귀호출예제
꽁스짱
JAVA
0
1476
2021.02.16 00:38
class RecursionTest {
long factorial(int value) {
if(value <= 1) return 1L;
return value*factorial(value-1);
}
public static void main(String[] args) {
if (args.length<1) {
System.out.println("Usage : java RecursionTest number ");
System.exit(1);
}
int value = Integer.parseInt(args[0]);
RecursionTest r = new RecursionTest();
long fact = r.factorial(value);
System.out.println(value + "! = " + fact);
}
}