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을 감싸고 있을까 클래스가..

+ Recent posts