.
Previous Next

Write a JAVA program to reverse the string?

/*JAVA Program to reverse the String */
public class ReverseString {
     public static void main(String[] args) {
           String str = "abcdef"; /* give input String here */
           String rev="";     
           int length = str.length();
           for (int i = length - 1; i >= 0; i--) {
                rev = rev + str.charAt(i);
           }
           System.out.println("Given  String  : "+str);
           System.out.println("Reverse String : "+rev);
     }

}
Previous Next