I’m having a few problems with a java guessing game. I’m supposed to have my code think up a random number and then prompt the user to input what I’m thinking until they get it right. I have a bug in my program because it always says the number is lower whether it is higher or lower but when I input the max number, it says I got it right. I don’t know where I went wrong. Any help is much appreciated! I’m going to link my code and the assignment specifications: http://courses.cs.washington.edu/courses/cse142/16wi/homework/5/spec.pdf import java.util.*;public class GuessingGame { public static void main(String[] args) { game(); statistics(); } public static void game() { Random random = new Random(); Scanner console = new Scanner(System.in); int num = random.nextInt(50); int guess = 0; int guess_count = 0; System.out.println(“I’m thinking of a number between 1 and ” + num); while (guess != num) { System.out.println(“Your guess? “); guess = console.nextInt(); guess_count++; if (guess > num) { System.out.println(“It’s higher.”); } else if (guess < num) { System.out.println("It's lower."); } else { System.out.println("You got it right in " + guess_count + " guesses"); } } System.out.println("Do you want to play again? "); System.out.println(); } public static void statistics() { System.out.println("Overall results:"); System.out.println("Total games = "); System.out.println("Total guesses = "); System.out.println("Guesses/game = "); System.out.println("Best game = "); }}
Why Choose Us
- 100% non-plagiarized Papers
- 24/7 /365 Service Available
- Affordable Prices
- Any Paper, Urgency, and Subject
- Will complete your papers in 6 hours
- On-time Delivery
- Money-back and Privacy guarantees
- Unlimited Amendments upon request
- Satisfaction guarantee
How it Works
- Click on the “Place Order” tab at the top menu or “Order Now” icon at the bottom and a new page will appear with an order form to be filled.
- Fill in your paper’s requirements in the "PAPER DETAILS" section.
- Fill in your paper’s academic level, deadline, and the required number of pages from the drop-down menus.
- Click “CREATE ACCOUNT & SIGN IN” to enter your registration details and get an account with us for record-keeping and then, click on “PROCEED TO CHECKOUT” at the bottom of the page.
- From there, the payment sections will show, follow the guided payment process and your order will be available for our writing team to work on it.