Skip to main content

Reverse a string [EASIEST]

Question:
Reverse a given string 

Code:

import java.util.*;
import java.lang.*;
import java.io.*;

class Solution {
public static void main (String[] args) {
//code
Scanner sc = new Scanner (System.in);
int m = sc.nextInt();
for(int i=0;i<m;i++){
   String str = sc.next();
   //String str ="malayalam";
   char[] c= str.toCharArray();
   for(int j=c.length-1;j>=0;j--){
       System.out.print(c[j]);
   }
   System.out.println();
}
}

}

Comments