Can't get this "Guess the number" game to work! | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 2

Can't get this "Guess the number" game to work!

Hello, I need help to get this code to work. I made it in Eclipse, its Java language! It's supposed to tell you If your guess is too high or too low based on a random number which it generates when you run it, but it spits out both "Your number is too low" and "Your number is too high" Help please!! Code: import java.util.Random; import java.util.Scanner; public class game1 { public static int number, guess, maxValue; public static Scanner scan; public static Random rand; public static void main(String[] args) { scan = new Scanner(System.in); rand = new Random(); number = rand.nextInt(101); System.out.println("Please enter a guess: "); while (guess != number) { guess = scan.nextInt(); if (guess > number); {System.out.println("Your guess is too low");} if (guess < number); {System.out.println("Your guess is too high");} }}}

5th Mar 2017, 1:59 PM
Joel
0 Respuestas