Course Hero Logo

Monster Recursion Packet.pdf - Recursion APCS MC Practice...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 5 out of 31 pages.

RecursionAPCS MC Practice1.What is the result whenprintnum(52)is called?public void printNumber (int n){if (n>=0){printNumber (n-1);__________System.out.print (n);}}2.What value is returned whenmysterySum(5)is called?__________public int mysterySum (int n){if (n == 0)return 0;elsereturn 3 + mysterySum(n - 1);}
3.What is the output whenmysterySum2(5)is called?__________
4.What is the output frommystery(4321)?__________
}
5.What is returned as the result ofmystery(7)?__________public int mystery (int n)
6.The following method will return true, if and only if:__________(A)s contains two or more of the same characters(B)s contains two or more of the same characters in a row(C)s starts with two or more of the same characters(D)s ends with two or more of the same characters(E)s.charAt(0) == s.charAt(1)public boolean check (String s){return s.length ( )>= 2 && (s.charAt(0) == s.charAt(1)|| check(s.substring(1)));}
7.What is returned by thecall mystery(0, 4, 5)when__________arr = {1, 2, 3, 5, 7}?
8.What value is returned by the callsomething(4,6)?__________46
9.The procedure callmystery(38)will yield as output which of the__________following sequences of numbers?
10.Given the input line ABCD and 0, what does the following method print?__________(A) ABCDCBA(B)ABBCCCDDDD(C)ABBCCCDDDDDDDDCCCBBA(D) AABABCABCDABCDABCABA(E)ABBCCCDDDDDDDDCCCCBBBBAAAApublic void processLine(String str, int pos)//precondition: str = “ABCD”, pos=0{if(pos < str.length){int i;for(i=0; i<=pos; i++)System.out.println(str.substring(pos, pos+1) );processLine(str, pos + 1);for(i=0; i<=pos; i++)System.out.println( str.substring(pos, pos+1) );}}

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 31 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
Montague
Tags
Recursion, Subroutine, Return statement, Control flow, Void type, following method

Newly uploaded documents

Show More

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture