Support Forums
My second program: Guessing Game - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Java Programming (https://www.supportforums.net/forumdisplay.php?fid=22)
+---- Thread: My second program: Guessing Game (/showthread.php?tid=3232)



My second program: Guessing Game - nevets04 - 11-29-2009

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);
            }
            
    }
}