계승을 계산하는 재귀 적 방법을 만들었지 만 주 방법에서는 for 루프를 사용하여 계승의 목록을 계산했습니다. 기본 방법에서 루프를 사용하지 않고 계승 목록을 계산하는 방법이 있습니까?루프를 사용하지 않고 계승 값을 인쇄하려면 어떻게해야합니까?
코드 : 그것은 당신이 "목록을 계산"뜻을 정확하게에 따라 다르지만,이 같은 일 인쇄
public class FactInt {
public static void main(String[] args) {
for (int n = 1; n < 11; n++)
System.out.println(factorial(n));
}
//Calculates the factorial of integer n
public static int factorial(int n) {
if (n == 0)
return 1;
else
return n*factorial(n-1);
}
}
@Plasmarob 계승을 인쇄합니다. – Vallentin
@Plasmarob 틀렸어. 그러나 기본 케이스의 인쇄는 생략합니다. –
정확합니다. – Plasmarob