Simple Java program to reverse a String

This Program is a to reverse a String in Java
charAt Method is used extract Characters from the string

The program as follows

import java.util.*;
class ReverseString
{
   public static void main(String args[])
   {
      String original, reverse = "";
      Scanner in = new Scanner(System.in);
      System.out.println("Enter the string to reverse");
      original = in.nextLine();
      int length = original.length();
      for ( int i = length - 1 ; i >= 0 ; i-- )
         reverse = reverse + original.charAt(i);
      System.out.println("Reverse of entered string is: "+reverse);
   }
}

By using StringBuffer class Reverse string 
(contains a method reverse which can be used to reverse or invert an object of this class.)

 

class InvertString
{
   public static void main(String args[])
   {
      StringBuffer a = new StringBuffer("i love java");
      System.out.println(a.reverse());
   }
}
Share Your Comments
Previous Payroll Management System Project C#.Net
Next C# Program to Print Pyramid From Console Application

About author

Aamir Shaikh
Aamir Shaikh 1370 posts

A Blogger, SEO Analyst and passionate Web Developer from India. Believes in hard work and continues working to achieve success.

View all posts by this author →

You might also like