Kotlinlearncs.online LogoJava
Return to List

Homework: Check Top Ten Movies

Created By: Ayesha Ahmed
/ Version: 2023.7.0

You asked all your friends to rank a list of 10 movies that you gave them, from 0 for the best to 9 for the worst. (Because you're a computer scientist, you always number starting at zero!)

Let's write a method to ensure that the array of rankings provided by each of your friends is valid. To be valid, the int[] needs to not be null, have 10 elements, and contain all int values from 0 to 9, inclusive. However, the values in the array can be in any order! So the array {1, 7, 5, 2, 3, 9, 0, 6, 4, 8} is valid.

Create a method named checkTopTenList that accepts an int[] and returns true if it is a valid top ten list according to the rules above, and false otherwise. Do not modify the contents of the passed array, since if you do how will you remember what your friend picked? Note that there are several ways to approach this problem that will work.

Related Lessons

Stuck? You may find these lessons helpful: