import java.util.Scanner;
class Factorial {
public static void main(String args[]) {
int n, c, fact = 1;
System.out.println("Enter an integer to calculate it's factorial");
Scanner in = new Scanner(System.in);
n = in.nextInt();
if (n < 0)
System.out.println("Number should be non-negative.");
else
{
for (c = 1 ; c <= n ; c++)
fact = fact*c;
System.out.println("Factorial of "+n+" is = "+fact);
}
}
}
숫자의 계승을 찾는이 코드에서 "fact = fact * c"부분을 얻지 못합니다. 사실 나는 c의 새로운 곱셈 계수로 "업데이트"되었기 때문에 그 숫자가 곱해진다는 것을 알고 있습니다.사실 = 사실 * c ?? 어떻게 작동합니까?
예 : n = 3, c = 1,2,3 및 fact = 1 .. 그러면 프로세스는 (1 * 1) * (1 * 2) * (1 * 3) = 6 ?
당신이 "숫자가 번성 할"의미합니까? – harold
디버거에서 코드를 단계별로 실행하면 각 코드 행의 내용을 볼 수 있습니다. –
(부적절한 팁 :'사실 * = c') – Rogue