Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My second program: Guessing Game
#1
Code:
import java.util.*;
public class random
{
    public static void main(String[] args)
    {
        Scanner num = new Scanner(System.in);
        int guess;
        Random generator = new Random();
        int number = generator.nextInt(10);
        System.out.print("Guess a number?: ");
        guess = num.nextInt();
        if (number == guess)
            System.out.println("You Win!");
        else
            {
            System.out.println("You Lose...");
            System.out.print("The number was ");
            System.out.println(number);
            }
            
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)