package ex06;
public class Ex19 {
public static void main(String[] args) {
int result = fact(5);
System.out.println(result);
}
public static int fact(int num) {
if(num>0)
return 2 * fact(num-1);
else
return 1;
}
}
문제는 숫자 2를 5번 곱하게 하는것이다.
이것을 팩토리얼로 구하는 방법이다.
'java' 카테고리의 다른 글
상속클래스 의 오버로딩 (0) | 2024.01.23 |
---|---|
상속 클래스 (0) | 2024.01.22 |
메소드 오버로딩 (0) | 2024.01.19 |
private 함수 (정보 은닉) (0) | 2024.01.18 |
tri 클래스를 호출(생성자와 매서드) (0) | 2024.01.17 |