Terrible Chandu From Hacker Earth

Chandu is a bad student. Once his teacher asked him to print the reverse of a given string. He took three hours to solve it. The teacher got agitated at Chandu and asked you the same question. Can you solve it?
Input:
The first line contains an integer T, denoting the number of test cases.
Each test case contains a string S, comprising of only lower case letters.
Output:
For each test case, print the reverse of the string S.

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class TerribleChandu {

public static void main(String[] args) 
{
Scanner scn=new Scanner(System.in);
System.out.println("Type Test cases");
int n=scn.nextInt();
String s1="";
String [] str=new String[n];
List<String> list=new ArrayList();
for(int i=0;i<str.length;i++)
    {
list.add(scn.next());
}
for(String l:list) 
     {
System.out.println(reverse(l.toLowerCase()));
}
}
public static String reverse(String str)
{
String nstr="";
char c;
for(int i=str.length()-1;i>=0;i--)
     {
c=str.charAt(i);
nstr+=c;
}
return nstr;
}
}

Post a Comment

Previous Post Next Post