Take-home labs are not graded and are for your own practice. Your lab tutor may discuss some of the exercises with you in odd weeks' lab sessions if necessary. Please take note of the following issues before attempting the labs:
This lab requires you to do two exercises. You are advised to review the materials covered in lecture 8 recursion before attempting this lab assignment. You should not use syntax or constructs not yet covered in lectures.
You are to Write a recursive method that finds the top 2 values in an unsorted array a[] of integers, where the array and its size are given as parameters. Note that the array may contain duplicate values.
Modify the skeleton file TopTwo.java for the above task.
Check sample runs for input and output format; submit your program through CourseMarker.
Four sample runs are shown below using interactive input (user's input shown in blue; essential output shown in bold purple).
$ javac TopTwo.java $ java TopTwo Enter the size of the array: 2 Enter array values: 5 11 top = 11, 2nd top = 5
Enter the size of the array: 6 Enter array values: 11 72 81 -108 81 14 top = 81, 2nd top = 81
Enter the size of the array: 6 Enter array values: 2 5 7 3 6 9 top = 9, 2nd top = 7
Enter the size of the array: 9 Enter array values: 2 5 7 9 10 5 10 3 10 top = 10, 2nd top = 10
The time below is an estimate of how much time we expect you to spend on this exercise. If you need to spend a lot more time than this, it is an indication that some help (or more practice) might be needed.
As the question is not easy, you are allowed to modify the skeleton file in any "unauthorized" way if you really can't figure out the idea of the designer. Discuss with your lab tutor for more.
Write a recursive method that print an input string in a reverse "V" shape and then a "V" shape as below:
***4***
**3*5**
*2***6*
1*****7
1*****7
*2***6*
**3*5**
***4***
**cd**
*b**e*
a****f
a****f
*b**e*
**cd**
Complete VShape.java for the above task.
Check sample run for input and output format; submit your program through CourseMarker.
Two sample runs based on above sample1.data is shown below using interactive input (user's input shown in blue; essential output shown in bold purple).
$ javac VShape.java $ java VShape Enter a string: abcdef **cd** *b**e* a****f a****f *b**e* **cd**
Enter a string: bb bb bb
The time below is an estimate of how much time we expect you to spend on this exercise. If you need to spend a lot more time than this, it is an indication that some help (or more practice) might be needed.
You may find this exercise quite difficult. In that case, discuss with your lab tutor for ideas and approaches.