Given a string, the task is to reverse it.
For example, if the string is "Hello" , reversed string is "olleH".
Complete the function reverseString() given in the editor that accepts a string & reverses it.
Input Format:
First line inputs numberof Testcases t
Then t strings followin each line
Output Format:
For each testcase output the reversed string
Sample Input 1
1
codequotient
Sample Output 1
tneitouqedoc
Sample Input 2
1
programming
Sample Output 2
gnimmargorp
// Return the reversed string
static String reverseString(String str) {
// Write your code here
char[] chars = str.toCharArray();
int i = 0;
int j= chars.length-1;
while(i<j){
char temp = chars[i];
chars[i] = chars[j];
chars[j] = temp;
i++;
j--;
}
return new String(chars);
}