I have a question about the practice problem of GFG, The question is given below:-
Given a string S as input. You have to reverse the given string.
Input: The first line of input contains a single integer T which denotes the number of test cases. T test cases follows, first line of each test case contains a string S.
Output: Corresponding to each test case, print the string S in reverse order.
I also attached solution of this but when I compile the code it only print one test case not all the test case.
For Input:
2 YSlxoBxAqYvIe4HxC4qO hibxuvax1MwiWYQzDEf2your output is: Oq4CxH4eIvYqAxBoxlSY
import java.util.*;
import java.lang.*;
import java.io.*;
class GFG {
public static void main (String[] args) {
//code
Scanner in = new Scanner(System.in);
int T = in.nextInt();
for(int j = 1; j<=T; j++) {
String S = in.nextLine();
char temp;
char[] arr = S.toCharArray();
int len = arr.length;
for(int i=0; i<(S.length())/2; i++,len--){
temp = arr[i];
arr[i] = arr[len-1];
arr[len-1] = temp;
}
System.out.println(String.valueOf(arr));
}
}
}