Given a String, return an array of char values that contains thecharacters of the string in reverse order. For example, if thestring is “Java”, the resulting array will contain the characters{‘a’, ‘v’, ‘a’, ‘J’}.
Examples:
reverseStringToArray(“Java”) -> {‘a’, ‘v’, ‘a’, ‘J’}reverseStringToArray(“This is a test.”) -> {‘.’, ‘t’, ‘s’, ‘e’, ‘t’, ‘ ‘, ‘a’, ‘ ‘, ‘s’, ‘i’, ‘ ‘, ‘s’, ‘i’, ‘h’, ‘T’}
*No printing, no scanners, just code that returns any possiblestring in reverse order as shown in the examples above*
*Do in Java language please*
public char[] reverseStringToArray(String str)
{
*ENTER CODE HERE*
}
Answer
public char[] reverseStringToArray(String str){ char arr[] = new char[str.length()];
OR
OR