can i have a recursion version of this one? or is this already recursion? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

can i have a recursion version of this one? or is this already recursion?

just my homework thank youu https://code.sololearn.com/cPcI0byFP41U/?ref=app

24th Feb 2022, 2:51 PM
Japheth
8 Antworten
+ 3
Japheth How you are doing? That's a method which should outside the other method mean you cannot write inside main method.
24th Feb 2022, 4:43 PM
A͢J
A͢J - avatar
+ 1
Japheth Recursion means calling method itself. This is an example: public static int sum(int n) { if (n < 0) return 0; else return n + sum(n - 1); }
24th Feb 2022, 3:44 PM
A͢J
A͢J - avatar
+ 1
A͢J will study that thank you so much will sleep for now
24th Feb 2022, 3:46 PM
Japheth
0
A͢J the int n is supposed to be?
24th Feb 2022, 3:47 PM
Japheth
0
Japheth int n - it is an argument which should be pass from outside like System.out.println(sum(10)); //here n = 10
24th Feb 2022, 3:50 PM
A͢J
A͢J - avatar
0
ohh and saying like // here n = 10 which is an integer
24th Feb 2022, 3:57 PM
Japheth
0
error occurs said i should include semicolon here public static int sum(int n) {
24th Feb 2022, 4:00 PM
Japheth
0
syntax error on token "(", ;expected
24th Feb 2022, 4:01 PM
Japheth