Question: As an example, if the values were 1 , 2 , and 4 , and the guess was 7 , the score would be 0

As an example, if the values were 1,2, and 4, and the guess was 7, the score would be 0a perfect score! However, if the values were 1,2, and 8, and the guess was 7, the score would be 4. And if the the values were 2,2, and 5, and the guess was 124, the score would be 115.
Write a snippet of code (not a method) that computes the score of a game. The values on the cards will be stored in an existing int array named values, and the guess in an int variable named guess. You should declare an int variable score and set its value to the score of that game. Do not modify values or guess.
You will need to compute the sum of the values in the array! You may also find the Math.abs method helpful when completing this problem, but it is not required.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!