I'm having to make a recursive function that will receive a stack of "int" and output the sum of the squares of the elements in the stack. Here is what I have
public int sum_sqr_rec(Stack<Integer> stk){
int sum = 0;
for (int i=0; i<stk.size(); i++){
sum += (stk.get(i) * stk.get(i));
}
return sum;
}
if (stk.empty()) return 0; int i = stk.pop(); return i*i + sum_sqr_rec(stk);