Advertisement
DulcetAirman

Recursive method for sum

May 9th, 2015
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.16 KB | None | 0 0
  1.   public static int sum(final List<Integer> list) {
  2.     if (list.isEmpty())
  3.       return 0;
  4.     return list.get(0) + sum(list.subList(1, list.size()));
  5.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement