Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Random Number Generator

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Thanked 0 Times in 0 Posts

    Default Random Number Generator

    I have to generate two random numbers, add them, and let the user type in the answer, and display if they are correct and if not give them the correct answer. I can't figure out how to know what the correct answer is, any hints?
    This is what I have so far . . . .

    a =(int) Math.random()*9 +1;
    b= (int) Math.random()*9 +1;
    problem = a + b;
    System.out.println("+", b);
    Last edited by pbrockway2; April 5th, 2013 at 12:56 AM. Reason: code tags corrected

  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Thanked 206 Times in 182 Posts

    Default Re: Random Number Generator

    I can't figure out how to know what the correct answer is
    From that snippet of code, it appears that problem is the correct answer (ie it is a and b added together).

Similar Threads

  1. Random Number Generator Always gives 0
    By tlckl3m3elmo in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 11th, 2012, 03:09 PM
  2. Random math problem generator?
    By CamCompetes in forum Member Introductions
    Replies: 1
    Last Post: March 9th, 2012, 02:42 PM
  3. My random generator isn't working. Please help!
    By tripline in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 5th, 2011, 10:03 AM
  4. random number generator
    By java3 in forum Loops & Control Statements
    Replies: 4
    Last Post: February 21st, 2011, 12:00 PM
  5. [SOLVED] Random number method implementation
    By big_c in forum Java Theory & Questions
    Replies: 2
    Last Post: April 15th, 2009, 01:10 PM