Answers for "write a java program to reverse a string"

3

reverse string java

String string="whatever";
String reverse = new StringBuffer(string).reverse().toString();
System.out.println(reverse);
Posted by: Guest on October-14-2020
2

Reverse a string in java without using reverse function

// Reverse a string in java without using reverse function
import java.util.Scanner;
public class ReverseWithoutFunction 
{
   public static void main(String[] args) 
   {
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter a string: ");
      String strInput = sc.nextLine();
      int len = strInput.length();
      String strReverse = "";
      System.out.println("Reverse a string without using reverse function: ");
      for(int a = len - 1; a >= 0; a--)
      {
         strReverse = strReverse + strInput.charAt(a);
      }
      System.out.println(strReverse);
      sc.close();
   }
}
Posted by: Guest on February-19-2021

Code answers related to "write a java program to reverse a string"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language