Java
-
문자열 뒤집기Computer Engineering/자료구조 2019. 9. 7. 22:03
- Java public static void reverse(char[] s, int index) { if(index==0) { return; }else { System.out.print(s[index-1]); reverse(s, index-1); } } public static void main(String[] args) { char[] s = {'h','e','l','l','o'}; reverse(s, s.length); } public static void reverse(char[] s, int f, int t) { if(f>t) { return; }else { reverse(s, f+1, t); System.out.print(s[f]); } } public static void main(Strin..
-
재귀적 팩토리얼Computer Engineering/자료구조 2019. 9. 7. 21:50
- Java public static int factorial(int s) { if(s==1) return 1; else return (s * factorial(s-1)); } public static void main(String[] args) { System.out.println(factorial(4)); } - Swift func factorial(item: Int) -> Int { if item == 1 { return 1 }else { return item * factorial(item: item-1) } } print(factorial(item: 4))