Reverse a String in JAVA - 👑 सार्थक मुंड S3 🤴🏻

Reverse a String in JAVA

Reverse a Srring in JAVA

Write a program in java to accepts line of strings and display the strings in reverse order.

import java.util.*;
class Reverse
{
  public static void main()
  {
    String orig, rev = "";
    Scanner in = new Scanner(System.in);
    System.out.println("Enter a string to reverse");
    orig = in.nextLine();
    int length = orig.length();
    for (int i = length - 1 ; i >= 0 ; i--)
      rev = rev + orig.charAt(i);
    System.out.println("Reverse of the string: " + rev);
  }
}
Reverse a Srring in JAVA
Output

"OR"

class RevStr
{
  public static void main()
  {
     StringBuffer a = new StringBuffer("Sarthak Mund S3");
     System.out.println("Reversed Steing is : "+a.reverse());
  }

}
Reverse a String in JAVA
OutPut

Must Read :-

  1. Blogger Tutorial
  2. C Programs
  3. C++ Programs
  4. Java Programs
  5. Python Programs
  6. Programming Notes 
  7. Questions & Answers
  8. My Codes : HTML, CSS & JS
Previous article
Next article

Leave Comments

Post a Comment

Articles Ads

Articles Ads 1

Articles Ads 2

Advertisement Ads