Recursive Method Output
What is the printed output when the program above executes?
public class Main {
public static void printPattern(int n) {
if(n < 1)
return;
printPattern(n - 1);
System.out.print(n + " ");
}
public static void main(String[] args) {
printPattern(4);
}
}
A
4 1 3 2
B
1 2 3 4
C
1 3 2 4
D
4 3 2 1
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | hitrishabhatia | 1 | 1 | 0m 00s | 100 |
| #2 | sgarv2513 | 1 | 2 | 0m 00s | 90 |
| #3 | parth.taur227 | 2 | 2 | 2m 51s | 29 |
| #4 | kazvin.tjakradinata | 1 | 3 | 1m 02s | 18 |
| #5 | lsj08030922 | 0 | 2 | 0m 00s | -20 |
| #6 | y.seong2027 | 1 | 2 | 2m 00s | -30 |
| #7 | namansoin000 | 0 | 1 | 0m 49s | -59 |
| #8 | suhanakochhar006 | 1 | 3 | 3m 53s | -153 |
| #9 | bommasam000 | 3 | 13 | 44m 35s | -2,475 |
| #10 | geethasailaja | 1 | 2 | 56m 09s | -3,279 |
Items per page:
10
1 – 10 of 10
APFIVE