Program to reverse a string in Java

Java-Expoit















import java.util.*;

class ReverseString
{
   public static void main(String args[])
   {
      String original, reverse = "";
      Scanner in = new Scanner(System.in);

      System.out.println("Enter a 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);
   }
}
Output
reverse string

Discover more from PlusDigit

Subscribe to get the latest posts sent to your email.

Discover more from PlusDigit

Subscribe now to keep reading and get access to the full archive.

Continue reading

AdBlock Detected!

Please disable your AdBlocker to access this website.

Once disabled, this message will disappear automatically.