Question

Java Programming - Write a program that generates two random integers, both in the range 25...

Java Programming - Write a program that generates two random integers, both in the range 25 to 75, inclusive. Use the Math class. Print both integers and then display the positive difference between the two integers, but use a selection. Do not use the absolute value method of the Math class.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I did not quite understand what you meant by "use a selection", but I gave it a shot anyway. Please drop a comment if there's a problem.

//---------OUTPUT----------

The integers generated are: 47, 66

The positive difference between both integer: 19

//------------------

import java.util.*;

public class Main {

    public static void main(String[] args) {

        //generate the first integer

        int x = (int) (25 + Math.random() * (76-25));

        //generate the second integer

        int y = (int) (25 + Math.random() * (76-25));

        //prints the integers

        System.out.println("The integers generated are: " + x+", "+y);

        //finds the difference

        int z = (x - y);

        //checks if second integer is greater

        if (y > x)

            //calculates the diferece again

            z = (y - x);

        System.out.println("The positive difference between both integer: " + z);

    }

}

Add a comment
Know the answer?
Add Answer to:
Java Programming - Write a program that generates two random integers, both in the range 25...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT