Created
August 12, 2019 09:26
-
-
Save gauravkukade/7ca435a229ad4dc2a963a7b48f3aa314 to your computer and use it in GitHub Desktop.
A Java program to reverse a string. We are using 'charAt()' method of the String class to get all char and arrange it in descending order to get a reverse string. This program is embedded at https://coderolls.com/reverse-a-string-in-java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A Java program to reverse a string. | |
* We are using 'charAt()' method of the String class to get all char and arrange it in | |
* descending order to get a reverse string. | |
* | |
* @author Gaurav Kukade at coderolls.com | |
*/ | |
public class ReverseString { | |
public static void main(String[] args) { | |
String blogName = "coderolls.com"; | |
String reversedString = ""; | |
for(int i = blogName.length()-1; i>=0; i--){ | |
reversedString = reversedString + blogName.charAt(i); | |
} | |
System.out.print("The reversed string of the '"+blogName+"' is: " ); | |
System.out.println(reversedString); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment