GuessNum Lab

Um programa simples que demonstra como usar java.util.Random
o computador calcula um número ‘aleatório’ e o usuário tenta adivinhar qual é com base nas dicas “muito alto” ou “muito baixo”

import java.util.Scanner;
import java.util.Random;

public class GuessNum
{
private Random ranNum = new Random();
private Scanner input = new Scanner(System.in);
private int magicNum;
private int guess;
private int counter;

public void guessing()
{
magicNum
= 1 + ranNum.nextInt(1000);

System.out.println("Take a guess: ");
guess
= input.nextInt();
do
{
if(guess == 99999)
{
System.out.printf("%dn", magicNum);
System.out.println("cheater, choose again: ");
guess
= input.nextInt();
}
else if (guess > magicNum)
{
System.out.println("your number was too high :( choose again: ");
guess
= input.nextInt();
}
else if (guess < magicNum)
{
System.out.println("your number was too low :( choose again: ");
guess
= input.nextInt();
}
counter
++;
}while (guess != magicNum);
System.out.printf("YAY!! the magic num is %d you guessed right!! and it only took you %d times :P n", magicNum, counter);
}

}