Ask Question
28 October, 04:40

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. 28 October, 05:59
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers