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
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.
+ 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);
}
+ 1
A͢J will study that thank you so much will sleep for now
0
A͢J
the int n is supposed to be?
0
Japheth
int n - it is an argument which should be pass from outside like
System.out.println(sum(10)); //here n = 10
0
ohh and saying like // here n = 10 which is an integer
0
error occurs said i should include semicolon here
public static int sum(int n) {
0
syntax error on token "(", ;expected