[java] 재귀로 알아보는 팩토리얼

Mr.SQL·2020년 11월 23일
0

재귀로 알아보는 팩토리얼

public class Factorial {
	
	public static void main(String[] args) {
		int input = 4; // 4!
		
		System.out.println(fact(input));
	}

	public static int fact(int n) {
		if (n <= 1)
			return n;
		else 
			return fact(n-1) * n;
	}
}


출처: https://marobiana.tistory.com/79 [Take Action]

profile
Mr.SQL velog에 오신것을 환영합니다.

0개의 댓글