Write a java program to reverse a string

We are discussing java program to reverse a string using following ways

  1. Java program to reverse a string using StringBuffer or StringBuilder class
  2. Java program to reverse a string using Loops(Iteration)

Java program to reverse a string using StringBuffer or StringBuilder class

Output

Java program to reverse a string using Loops(Iteration)

Copy and reverse the string

write a program to reverse a string

Here getting input from the user

converted into character array using toCharArray() of String

Initialize the other character array with the same length as c character array.

Loop char array c in reverse order and r in forwarding order.

this will copy character array c in reverse order to r.

converted char array r to String

print both character array

Output

Read More

  1. Duplicate Number between 1 to n numbers
  2. Print vowels in a String
  3. Sum of two numbers using command line arguments
  4. Prime number program in java using while loop
  5. Print vowels in a String
  6. Square Star Pattern