4. What does the following method do: public static void rp4(int x) if (x0) return 0; returnx + rp4(x-1); Show transcribed image text 4. What does the following method do: public static void rp4(int x) if (x0) return 0; returnx + rp4(x-1);
Answer
This recursive method calculates and returns the sum of first x natural numbers.so, rp4(x) returns 1+2+3+…+(x-1)+x