PROGRAM FOR REVERSE STRING

This is programe by using the for loop we can get the reverse of string.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import java.io.*;
public class ConStr
{
     public static void main(String[] args) throws IOException
     {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int len,length;
        String  reverse ="";
        System.out.println("Enter First String:");
        String str = bf.readLine();
        len=str.length();
        System.out.println("length of the string is:"+len);
        for ( int i = len - 1 ; i >= 0 ; i-- )
            reverse = reverse + str.charAt(i);
        System.out.println("Reverse of entered string is "+reverse);
    }
}

Output :Reverse String
gcdn