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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 3 of 3

Thread: Java Question

  1. #1
    Junior Member
    Join Date
    Sep 2022
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Java Question

    I am preparing for my java exam, so i am taking a reference from different book. There is a question is a book and I got confuse

    Write a program that generates 60 pairs of random integers (int) with values between 1 and 10 000. For each generated pair, use an if-else statement to classify the first value as greater than, less than, or equal to the second value. For output, display BOTH generated values, as well as the classification, in the format “Number 1 < classification > Number 2”, one number pair per output line, where < classification > is one of the phrases “less than,” “equals,” or “greater than.”

    I understand how I can use the if-else condition, but don’t understand the “generate 60 pairs of random integer”. I don’t need the solution just the explanation. Do I have to create 60 Arrays with every array only 2 random numbers can add it? And in the question it does not says that I have use array or for or while condition.

  2. #2
    Member
    Join Date
    Jun 2022
    Posts
    41
    Thanks
    1
    Thanked 3 Times in 2 Posts

    Default Re: Java Question

    I would create a function compareInts(int A, int B) that returns a string {"less than", "equals", "greater than"}
    Then how to generate 60 comparisons would become a separate chore, and entirely up to you.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java Question

    I don't see where an array is required. I would guess there would be a loop that iterates 60 times. The two random int values would be generated inside the loop, one pair for each iteration.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java question
    By empms in forum Java Theory & Questions
    Replies: 0
    Last Post: September 30th, 2013, 04:05 PM
  2. Java question. Please help me!
    By phosphenes in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 2nd, 2013, 12:26 PM
  3. Replies: 1
    Last Post: November 1st, 2012, 07:54 AM
  4. Challenging Java Question: Test your Java skill by grouping these terms
    By karthickk3 in forum Java Theory & Questions
    Replies: 3
    Last Post: July 18th, 2012, 10:10 PM
  5. help for this java question
    By marlontoyo in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 20th, 2011, 08:09 PM