Ask Question
19 May, 12:26

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 → '.'

+4
Answers (1)
  1. 19 May, 12:34
    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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers