| preferred AP College board partner for AP classes
medium Solved by 13 students
Recursive Method Output
< Prev
Next >

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

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1hitrishabhatia11 0m 00s 100
#2sgarv251312 0m 00s 90
#3parth.taur22722 2m 51s 29
#4kazvin.tjakradinata13 1m 02s 18
#5lsj0803092202 0m 00s -20
#6y.seong202712 2m 00s -30
#7chunxiangxu.cxu01 0m 41s -51
#8namansoin00001 0m 49s -59
#9suhanakochhar00613 3m 53s -153
#10meromaroseif13 4m 40s -200
Items per page:
10
1 – 10 of 12
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy