Download presentation
Presentation is loading. Please wait.
1
Lecture 12: Midterm Review Multiple choice quiz from pub website (see web page for link and use access code liang6e614 ) Homework 5: N Queens Sample midterm questions
2
Sample Question 1 Write a method –public static String reverse(String s) that returns the reverse of s. Use a loop and the length() and charAt() methods from the String class. Do not use recursion. Make sure your method works if s is the empty string.
3
Sample Question 2 Write a method –public static String reverse(String s) that, as in Question 1, returns the reverse of s, but instead of using a loop, use recursion. Use the charAt and substring methods. Note that, for example, if s is “abcdef”, then s.substring(2,4) is “cd”. Make sure your method works if s is the empty string.
4
Sample Question 3 Write a method –public int[] getEvenHalf(int[] x) that returns a new array consisting of every second element of x. It should work whether the length of x is even or odd, including length 0 (the empty array). For example, if the elements of x are 1 2 3 6 7 8 9 the method should return a new array with elements 1 3 7 9. The method should not change the array x. Remember that x.length is a data field, not a method. Also write a snippet of code that constructs a random int array and calls getEvenHalf.
5
Sample Question 4 Write a method equals for our Date class of Homework 4 in such a way that it overrides the equals method of the Object class. Give an example of a snippet of code that calls this method for which it is important to implement the Date equals method in this way, as opposed to the way you wrote it in Homework 4, which did not override the equals method of the Object class.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.