Program to Reverse a string in Java
public static String reverseString(String reverseString) {
StringBuffer reversedString = new StringBuffer();
char[] reverseArray = reverseString.toCharArray();
for(int i = reverseArray.length-1; i>=0; i--) {
reversedString.append(reverseArray[i]);
}
return reversedString.toString();
}
public static void main(String[] args) {
String reversedString = reverseString("Keshav");
System.out.println("Reversed String "+reversedString);
}
Comments
Post a Comment