Recursive Method Output
Consider the following class definition.
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);
}
}
What is printed as a result of executing the main method?
A
1 3 2 4
B
4 1 3 2
C
1 2 3 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 | chunxiangxu.cxu | 0 | 1 | 0m 41s | -51 |
| #8 | namansoin000 | 0 | 1 | 0m 49s | -59 |
| #9 | suhanakochhar006 | 1 | 3 | 3m 53s | -153 |
| #10 | meromaroseif | 1 | 3 | 4m 40s | -200 |
Items per page:
10
1 – 10 of 12
APFIVE