User chooses a number then checks if it matches the random number and loops again if you lose and stops until you win
import java.util.Scanner; public class GuessingGame2 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int number;/*from ww w .j a v a 2s.c o m*/ int CorrectGuess = (int) (Math.random() * 20) + 1; int counter; counter = 0; System.out.println("Enter a number between 1-20: "); number = scan.nextInt(); if (CorrectGuess == number) System.out.println("You won"); if (number != CorrectGuess) System.out.println("Better luck next time"); else System.out.println("Computers number: " + CorrectGuess); System.out.println("Players number: " + number); } }