Skip to content

Instantly share code, notes, and snippets.

@gauravkukade
Created August 12, 2019 09:26
Show Gist options
  • Save gauravkukade/7ca435a229ad4dc2a963a7b48f3aa314 to your computer and use it in GitHub Desktop.
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
/**
* 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