Ask Question
22 June, 05:43

public static char getRandomColor (Random random) - Using the random. nextInt (6) method call generate a random integer value between 0 and 5. The character to return for a particular integer will be: 0 → 'R' 1 → 'G' 2 → 'B' 3 → 'Y' 4 → '*' 5 → '.'

+3
Answers (1)
  1. 22 June, 09:16
    0
    public static char getRandomColor (Random random) {

    int number = random. nextInt (6);

    if (number = = 0) {

    return 'R';

    } else if (number = = 1) {

    return 'G';

    } else if (number = = 2) {

    return 'B';

    } else if (number = = 3) {

    return 'Y';

    } else if (number = = 4) {

    return '*';

    } else {

    return '.';

    }

    }

    Explanation:

    The function take random object as parameter. First, the a generated integer between 0 to 5 is assigned to number.

    Next, a block of if-else statement is use to check the generated random number and knows which character to return. If the number is 0, 'R' is returns. If the number is 1, 'G' is returns. If the number is 2, 'B' is returns. If the number is 3, ' Y' is returns. If the number is 4, '*' is returns. If the number is 5, '.' is returns.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “public static char getRandomColor (Random random) - Using the random. nextInt (6) method call generate a random integer value between 0 and ...” in 📘 Business if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers