reverse a string in java without using reverse function

Solutions on MaxInterview for reverse a string in java without using reverse function by the best coders in the world

showing results for - "reverse a string in java without using reverse function"
Anton
04 Nov 2018
1// Reverse a string in java without using reverse function
2import java.util.Scanner;
3public class ReverseWithoutFunction 
4{
5   public static void main(String[] args) 
6   {
7      Scanner sc = new Scanner(System.in);
8      System.out.println("Please enter a string: ");
9      String strInput = sc.nextLine();
10      int len = strInput.length();
11      String strReverse = "";
12      System.out.println("Reverse a string without using reverse function: ");
13      for(int a = len - 1; a >= 0; a--)
14      {
15         strReverse = strReverse + strInput.charAt(a);
16      }
17      System.out.println(strReverse);
18      sc.close();
19   }
20}
Bryn
10 Jun 2020
1As we know that String is immutable. String class do not have reverse() method.