Access over 20 million homework & study documents

(10 points) What is the output of the following recursive program cl

Content type
User Generated
Rating
Showing Page:
1/4
(10 points) What is the output of the following recursive
program? class testreoccur f public static void reoccur (int
count) f if (count >7) System.out.println(\"\") return; else f
System.out.print(count) reoccur (count + 1); public static
void main(Stringt args) reoccur(O)
Solution
(1)
Output of the given recursive program will be:
0
1
2
3
4
5
6
7
Call 1: Count: 0 Print 0 to console and call reoccur(1)
Call 2: Count: 1 Print 1 to console and call reoccur(2)
Call 3: Count: 2 Print 2 to console and call reoccur(3)
Call 4: Count: 3 Print 3 to console and call reoccur(4)
Call 5: Count: 4 Print 4 to console and call reoccur(5)
Call 6: Count: 5 Print 5 to console and call reoccur(6)

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/4
Call 7: Count: 6 Print 6 to console and call reoccur(7)
Call 8: Count: 7 Print 7 to console and call reoccur(8)
When count value is greater than 7, recursion gets
stopped.
--------------------------------------------------------------------------
---------------------------------------------------------------------------
-----------------
(2)
On execution, the main function calls the function
\"Countem\" by passing a line of text as parameter.
1. Function Countem stores received parameter in to a
variable str1.
2. Scanner class object is created by passing str1 to its
constructor.
3. Scanner class method usedelimiter(\"[^A-Za-z]+\") sets
the delimiter of Scanner object \"in\". String str1 is splitted
in to multiple tokens by using the delimiter.
4. String str1 is splitted into 20 tokens(words).
Word# : 1 Word: It
Word# : 2 Word: is
Word# : 3 Word: recommended
Word# : 4 Word: to
Word# : 5 Word: eat
Word# : 6 Word: meals
Word# : 7 Word: a

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/4

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 4 pages?
Access Now
Unformatted Attachment Preview
(10 points) What is the output of the following recursive program? class testreoccur f public static void reoccur (int count) f if (count >7) System.out.println( \"\") return; else f System.out.print(count) reoccur (count + 1); public static void main(Stringt args) reoccur(O) Solution (1) Output of the given recursive program will be: 0 1 2 3 4 5 6 7 Call 1: Count: 0 Print 0 to console and call reoccur(1) Call 2: Count: 1 Print 1 to console and call reoccur(2) Call 3: Count: 2 Print 2 to console and call reoccur(3) Call 4: Count: 3 Print 3 to console and call reoccur(4) Call 5: Count: 4 Print 4 to console and call reoccur(5) Call 6: Count: 5 Print 5 to console and call reoccur(6) Call 7: Count: 6 Print 6 to console and call reoccur(7) Call 8: Count: 7 Print 7 to console and call reoccur(8) When count value is greater than 7, recursion gets stopped. -------------------------------------------------------------------------------------------------------------------------------------------------------------------(2) On execution, the main function calls the function \"Countem\" by passing a line of text as parameter. 1. Function Countem stores received parameter in ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Just the thing I needed, saved me a lot of time.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4