Question

Exercise 22: Write a program that creates three random double variables a, b, and c and...

  1. Exercise 22: Write a program that creates three random double variables a, b, and c and assigns them values between 0 and 1 using the Math.random( ) method mentioned in the preceding exercise. It then does all of the following:

    1. It prints out the three values.

    2. It prints "All are tiny" if all three values are less than 0.5.

    3. Extra: It prints out "One is tiny" if exactly one of the three values is less than 0.5.

    4. Extra: It prints out "Only two are tiny" if exactly two of the three values are less than 0.5.

Extra: it prints if “None is tiny” if none of the values are less than 0.5.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class ThreeRandom {

    public static void main(String[] args) {
        double a = Math.random(), b = Math.random(), c = Math.random();

        System.out.println("Numbers are " + a + ", " + b + " and " + c);
        if (a < 0.5 && b < 0.5 && c < 0.5) {
            System.out.println("All are tiny");
        } else if((a < 0.5 && b < 0.5) || (b < 0.5 && c < 0.5) || (a < 0.5 && c < 0.5)) {
            System.out.println("Only two are tiny");
        } else if(a < 0.5 || b < 0.5 || c < 0.5) {
            System.out.println("One is tiny");
        } else {
            System.out.println("None is tiny");
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
Exercise 22: Write a program that creates three random double variables a, b, and c and...
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
  • Explain the code: Exercise 22: Write a program that creates three random double variables a, b,...

    Explain the code: Exercise 22: Write a program that creates three random double variables a, b, and c and assigns them values between 0 and 1 using the Math.random( ) method mentioned in the preceding exercise. It then does all of the following: It prints out the three values. It prints "All are tiny" if all three values are less than 0.5. It prints out "One is tiny" if exactly one of the three values is less than 0.5. It...

  • Variables lab Write a program that creates three variables: an int, a double, and a String. Put the value 113 into t...

    Variables lab Write a program that creates three variables: an int, a double, and a String. Put the value 113 into the first variable, the value .71828 into the second, and the value Computer Science" into the third. It does not matter what you call the variables... this time. Then, display the values of these three variables on the screen, one per line. This is room # 113 e is close to 2.71828 I am learning a bit about Computer...

  • Write a Python program that creates a set of ten elements with random numbers between 1...

    Write a Python program that creates a set of ten elements with random numbers between 1 and 100, and then prints out the values in sorted order

  • Write a program in C that creates an array of 100 random numbers from 0-99. The...

    Write a program in C that creates an array of 100 random numbers from 0-99. The program sums the random numbers and prints the sum.  It then writes the numbers to a new file using open, close and write. Then looks in the current directory for files that match the pattern “numbers.XXXX”. For each file, open the file and read the file. You can assume that the file will contain 100 integers. Sum the integers. Print the filename and the sum...

  • Program Instructions: Write a C++ program that uses a random number generator to generate a two...

    Program Instructions: Write a C++ program that uses a random number generator to generate a two digit positive integer and allows the user to perform one or more of the following operations: Double the number. Reverse the digits of the number. Raise the number to the power of 2, 3, or 4. Sum the digits of the number. If the number is a two digit number, then raise the first digit to the power of the second digit. If the...

  • ***** TO BE WRITTEN IN JAVA ***** Write an application that creates and prints a random...

    ***** TO BE WRITTEN IN JAVA ***** Write an application that creates and prints a random phone number of the form XXX-XXX-XXXX. Include the dashes in the output. Do not let the first three digits contain an 8 or 9 (but don't be more restrictive than that), and make sure that the second set of three digits is not greater than 742. Hint: Think through the easiest way to construct the phone number. Each digit does not have to be...

  • In Java. Write a program in a single file that: Main: Creates 10 random doubles, all...

    In Java. Write a program in a single file that: Main: Creates 10 random doubles, all between 1 and 11, Calls a class that writes 10 random doubles to a text file, one number per line. Calls a class that reads the text file and displays all the doubles and their sum accurate to two decimal places. There has to be three classes, main for create random numbers, one to write , one to read all in the same file...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • PYTHON 1- Write a program that creates a dictionary of the English words for all single...

    PYTHON 1- Write a program that creates a dictionary of the English words for all single digit numbers as follows: 1: 'one', 2: 'two', 3: 'three', etc. 2- Write a function called numConvert that receives the above dictionary and an integer number as parameters, and prints the English words for all the number's digits. For example, if the function receives 2311, it will print: two three one one 3- Test your program by adding a main function, which calls numConvert....

  • In a file called First SecondNext.java, write a program that: • Asks the user to enter...

    In a file called First SecondNext.java, write a program that: • Asks the user to enter a string that contains at least five letters. It is OK if your program crashes when the user enters a string with length less than 5. • Stores that string in a variable called s. • Creates a variable called "first", and sets it equal to the first letter of s. • Creates a variable called "second", and sets it equal to the second...

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