fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. List<Integer> vals = new ArrayList<>();
  13. vals.add(1);
  14. vals.add(2);
  15. vals.add(3);
  16. sumOfSquares(vals);
  17. for (int i = 0 ; i != vals.size(); i++) {
  18. System.out.println(vals.get(i));
  19. }
  20. }
  21.  
  22. public static int sumOfSquares(List<Integer> num) {
  23. if (num.isEmpty()) {
  24. return 0;
  25. }
  26. int hold= num.get(0)*num.get(0);
  27. num.add(1, hold);
  28.  
  29.  
  30. return num.get(1) + sumOfSquares(num.subList(2, num.size()));
  31. }
  32.  
  33.  
  34. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
1
1
2
4
3
9