Question: What is wrong with my code import java.util.Scanner; import java.util.Random; public class Project 2 { public static void main ( String [ ] args )
What is wrong with my code
import java.util.Scanner;
import java.util.Random;
public class Project
public static void mainString args
Scanner scnr new ScannerSystemin;
while true
System.out.println Guess your number";
System.out.println Guess my number";
System.out.println Exit";
int choice scnrnextInt;
if choice
guessYourNumber;
continue;
if choice
guessMyNumber;
continue;
if choice
System.out.printlnGoodbye;
break;
System.out.printlnInvalid input";
public static void guessYourNumber
System.out.printlnThink of a number from to ;
int low high tries ;
int maxTries ;
Scanner scnr new ScannerSystemin;
while tries maxTries
int guess low high;
tries;
System.out.printlnCPU guesses guess;
System.out.printlnType y if the number is correct, h if the number is higher, and l if the number is lower";
String cpuGuess scnrnextLinetoLowerCase;
if cpuGuessequalsy
System.out.printlnYou lose. Game over. :
;
return;
if cpuGuessequalsh
high guess ;
continue;
if cpuGuessequalsl
low guess ;
continue;
System.out.printlnInvalid input";
System.out.printlnYou got me You win! :
;
public static void guessMyNumber
Random randGen new Random;
int correctNum randGen.nextInt;
int tries ;
final int maxTries ;
Scanner scnr new ScannerSystemin;
System.out.printlnTry to guess the number I picked. From ;
while tries maxTries
System.out.printInput your guess: ;
int userGuess scnrnextInt;
tries;
if userGuess correctNum
System.out.printlnLower;
continue;
if userGuess correctNum
System.out.printlnHigher;
continue;
System.out.printlnCongratulations That was the number. You win! :;
return;
System.out.printlnAll attempts used. The number was correctNum You lose. Game over. :
;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
