
Concept explainers
Explanation of Solution
Program code:
RandomGuessMatch.java
//import the required header files
import java.util.Random;
import java.util.Scanner;
//define a class RandomGuessMatch
public class RandomGuessMatch
{
//define main() method
public static void main(String[] args)
{
//create the object of Random
Random random = new Random();
//create integer variable and set its value
int randNum = random.nextInt(5) + 1;
//create the object of Scanner class
Scanner sc = new Scanner(System.in);
//print the statement
System.out.println("Guess the number: ");
//create an integer variable guess and get its value
int guess = sc.nextInt();
//print the differnece between ransom value and guess value
System.out.println("Difference between the random number and the user’s guess = " + Math.abs(guess - randNum));
//print the value of randNum
System.out.println("The random number is: " + randNum);
//print true if guess value and random value are equal, false otherwise.
System.out...
Trending nowThis is a popular solution!

Chapter 2 Solutions
EBK JAVA PROGRAMMING
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr




