제곱수의+합

Source Code code format="java5" public class Squares { public static int[] terms = new int[100];

public static void main(String[] args) { System.out.println(getNumOfTerm(1)); System.out.println(getNumOfTerm(4)); System.out.println(getNumOfTerm(7)); System.out.println(getNumOfTerm(11)); System.out.println(getNumOfTerm(13)); }

public static int getNumOfTerm(int n) { // base case if(n == 0) { return 0; }

if(terms[n] != 0) { return terms[n]; }

// recursive case for(int i = n; ; i--) { if(n >= i*i) { int t = 1 + getNumOfTerm(n - i*i); terms[n] = t;               return t;            } }   } } code

Comment 재귀를 이용하였다.