public class Factorial {
public static void main(String[] args) {
Factorial fac = new Factorial();
System.out.println(fac.factorial1(3));
System.out.println(factorial2(3));;
}
public int factorial1 (int num) {
if (num == 1)
return 1;
return num * factorial1 ( num - 1 );
}
public static int factorial2 (int num) {
if (num == 1)
return 1;
return num * factorial2 ( num - 1 );
}
}
결과값

c++에서 java로 넘어오니 너무 느낌이 다르다...
ide도 바뀌고 Mac도 배우고 있고 왜 static으로 하면 바로 나오는지 모르겠다..
왜 main을 감싸고 있을까 클래스가..
'Java' 카테고리의 다른 글
| [백준] 2993번 : 세 부분 (0) | 2023.03.07 |
|---|---|
| [백준] 11478번 : 서로 다른 부분 문자열의 개수 (0) | 2023.03.02 |
| [백준] 9996번 : 한국이 그리울 땐 서버에 접속하지 (0) | 2023.03.01 |
| [백준] 11899번 : 괄호 끼워넣기 (0) | 2023.02.28 |
| 추상클래스와 인터페이스 차이 (1) | 2023.02.15 |