+ 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?") } }

28th Mar 2017, 6:49 PM
PaperGami T.
PaperGami T. - avatar
3 Respuestas
+ 14
To run correctly: if (myNumber == guessNumber){ This statement is not necessary: if (myNumber > guessNumber || myNumber < guessNumber) { You can delete it and the closing }.
28th Mar 2017, 7:26 PM
Tashi N
Tashi N - avatar
+ 5
thanks!
28th Mar 2017, 7:28 PM
PaperGami T.
PaperGami T. - avatar
+ 4
As you got yhe answer already. you may want to consider generating randomly a number to guess (avoiding floats)
28th Mar 2017, 8:20 PM
seamiki
seamiki - avatar