I am getting a wrong answer in TOANDFRO
This is my code. It works correctly on the given test cases.
import java.util.*;
public class toandfro
{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t!=0){
String st = sc.next();
int rows = st.length()/t;
StringBuilder sb = new StringBuilder();
String[] strings = new String[rows];
int abc = 0;
for(int i = 0; i<st.length(); i+=t){
String sub = st.substring(i, i+t);
if(i%2!=0){
sub = new StringBuilder(sub).reverse().toString();
}
strings[abc] = sub;
abc++;
}
for(int j = 0; j<t; j++){
for(int i = 0; i<rows; i++){
sb.append(strings[i].charAt(j));
}
}
System.out.println(sb.toString());
t = sc.nextInt();
}
}
}