Write a method called randomReverse that accepts a String array of people's names as input. The method will then randomly select a name from the array and return a reversed copy. For example, if the selected name is Bob, the output should be boB. Since the method should work for partially filled arrays, it will sometimes return null.
Please only use for loops, if statements, and the random class. Since it says to accept the names as inputs, I am assuming that means user input? Is that possible? Also, the question does not mention parameters, so if possible, please try not to use them. Please try not to use array list methods and string builders.
This is the code that I have for reversing the random name, but I am having issues on how to collect the strings as input as this code also does not account for partially filled arrays:
Random rand = new Random();
int randomNumber = rand.nextInt(names.length);
for(int i = names[randomNumber].length(); i > 0; --i) {
System.out.println(names[randomNumber].charAt(i - 1));
}