+ 5
How to make my code (guess my number) with Java and user input? sorry if something was mispelt. coppying from my computer.
import java.util.Scannner; public class Game{ public static void main(Strings[] args) { Scanner userNumber = new Scanner (System.in); boolean guessNumber = false; int myNumber=42; byte bonus=36; int guessNumber = userNumber. nextInt(); if (myNumber = guessNumber){ boolean guessNumber=true; int nice=bonus * guessNumber + guessNumber; System. out. println("Lucky guess! Score: "+nice); } else { if (myNumber > guessNumber || myNumber < guessNumber) { System. out. println("Nice try...Try again?") } }
3 Answers
+ 14
To run correctly:
if (myNumber == guessNumber){
This statement is not necessary:
if (myNumber > guessNumber || myNumber < guessNumber) {
You can delete it and the closing }.
+ 5
thanks!
+ 4
As you got yhe answer already. you may want to consider generating randomly a number to guess (avoiding floats)