Task: Write a Java String Class Reverse Program. You have to use only String class objects and String class built-in methods to reverse a user supplied string.
Logic behind Java String Reverse Program
You will use the following standard methods provided in String class:
- length() method to know the length of the original string.
- charAt(index) method to get a particular character from a string at given index.
- You will use + operator for string concatenation.
The Code of Java String Reverse Program
Output of Java String Reverse Program
Enter a String to Reverse: Hello Java
Original string=Hello Java
Reverse string=avaJ olleH
Enter a String to Reverse: Cricket Match
Original string=Cricket Match
Reverse string=hctaM tekcirC