Java Bootcamp – Workbooks and Challenges
)}

Workbook 6.5

From Java Bootcamp Resources -> Module 1 -> 6. Arrays, open Workbook 6.5.

High Score

You and your friends are playing Pac-Man. The one with the highest score wins a prize.

Task 1


Make a function that returns a random number between 0 and 50,000.

    /**
     *  Function name -- randomNumber
     *
     *  @return random number (int)
     *
     *  Inside the function
     *    - return a random number
     *
     */

Task 2


Create an array that stores 10 random numbers. Using a for loop, print the contents of the array:

Here are the scores: 14775 48328 7928 27102 21787 21063 38096 42711 32863 23707

  1. Print every element on the same line.

  2. Leave one space between each element.

Task 3


There is a variable highScore that starts at 0.

  • Using a for loop, find the highest score in the array and update highScore.

  • Print: \n\nThe highest score is: <highScore>. Give that man a cookie!

Hints


  1. Loop through every value in the array.

  2. Inside the loop, check if the current element is higher than the high score. If so, update the high score.

Good Luck!


Feedback Summary
4.8
39 students
5

92%
4

3%
3

0%
2

0%
1

5%
Written Reviews
There are no written reviews yet.