How to use BigInteger in Java - 2
May 31, 2023
1 min
Recursive calls call back the magnetic function in the function, and if there is no stopping condition, it is repeated indefinitely, so be careful.
public static void main(String[] args) {int result = sum(1, 4);System.out.println(result);}public static int sum(int start, int end) {if (end > start) { // Stop conditions preventing infinite recursive repetitionreturn end + sum(start, end - 1);} else {return end;}}