Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Have this code that wont complie dont know where its wrong. / need the Scanner class to get user input import java.util.Scanner; public class numberGuess

Have this code that wont complie dont know where its wrong.

/ need the Scanner class to get user input import java.util.Scanner;

public class numberGuess {

/** * @param args */ public static void main(String[] args) { // TODO: // // a. declare a final int, and assign a value of 6 as the guessed number int answer=num.nextInt(10)-4; // b. create a Scanner to get user input System.out.println("Guess a number from 1 to 10"); Scanner input = new Scanner(System.in); guess =input.nextInt(); // c. use a do {} while loop to prompt the user to enter an integer between 1 and 10, // assign the user input to an int, and compare to the guessing number do{ if (guess < 1 || guess > 10){ System.out.println("That is not a valid entry. Please try again: "); guess = input.nextInt(); }else if (guess > answer){ System.out.println("Too high, Try Again: "); guess = input.nextInt(); }else if (guess < answer){ System.out.println("Too low, Try Again: "); guess = input.nextInt(); }

} while (guess ! = answer); // d. if the number matches the guessed number, // print out a message that the number entered is correct. System.out.println("Entered number is correct");

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions