Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Thanks in advance, I want to write a Guess the number game as independently as possible but I need to parse and compare a random generated number and an Int Help!!! "Random Ran = new Random();

System.out.println("A Number Has been Generated");

System.out.println("Guess what it is...");

int a = System.in.read();

while ( Ran != a)"

share|improve this question

closed as off topic by Rinzwind, ajmitch, hhlp, fossfreedom Mar 24 '12 at 10:29

Questions on Ask Ubuntu are expected to relate to Ubuntu within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Questions on Ask Ubuntu - Stack Exchange are expected to generally relate to Ubuntu, within the scope defined in the faq. You should ask this on the coders version of stack! programmers.stackexchange.com –  Rinzwind Mar 24 '12 at 7:23

1 Answer 1

This is answer:

import java.util.Random;
import java.util.Scanner;
class game
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        Random randomGenerator = new Random();
        int randomInt = randomGenerator.nextInt(100);
        System.out.println("Number generated!,Guess it");
        int c = in.nextInt();
        while(c!=randomInt)
        {
            if(c>randomInt)
            {
                System.out.println("My number is lesser");
                c = in.nextInt();
            }
            if(c<randomInt)
            {
                System.out.println("My number is bigger");
                c = in.nextInt();
            }
            if(c==randomInt)
            {
                System.out.println("It is my number!!!");
                break;
            }
        }
    }
}
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.