백준
백준 27433 - Java
으엉어엉
2024. 9. 14. 19:47
728x90
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Factorial2 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
if(N>=0 && N<=20) {
long fact = 1;
for (int i = 1; i <= N; i++) {
fact *= i;
}
System.out.println(fact);
}
}
}
왜 틀렸나 했더니 fact를 integer로 받아서 범위 초과로 틀린 것이였다.
그래서 long으로 바꿔주었다.
728x90