jeudi 25 août 2016

How can I check whether an integar is within 5 numbers of a hidden random integar?

I am new to Java and am currently writing a project for school. It's a lucky guess game, I have create the code to generate a random number, and the user is trying to guess it. On the third and final attempt, I need a condition that checks whether the final guess is within 5 (both below and above) this random number.

Due to plagiarism concerns in my university, I will not be posting my code but I will note that my random number is assigned a named variable (randomNumber).

Is there something like: if (guess.isWithin(5) = randomNumber)

I know that's gibberish but hopefully you get what I mean.

Thank you.




Aucun commentaire:

Enregistrer un commentaire