You are here: Home / Topics / How to reverse a String in java? Can you write a program without using any java inbuilt methods?

How to reverse a String in java? Can you write a program without using any java inbuilt methods?

Filed under: Java on 2024-02-19 14:26:09

Solution: There are many ways to do it, some of them are:

Using for loop
Using recursion
Using StringBuffer

 

package sixDayProject;

public class ReverseStringExample {

public static void main(String[] args) {
 String str = "Hello Shyam";
 for(int i = str.length()-1; i>=0; i--) {
  System.out.print(str.charAt(i));
 }
}

}

About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.