Wings of Fire: An Autobiography
public class StringReverse {
public static void main(String[] args) {
String original, reverse =""; // declare two string variable
original = "Sample String"; //String to be reversed
int length = original.length(); //find length of string
for ( int i = length - 1 ; i >= 0 ; i-- )
reverse = reverse + original.charAt(i); //charAt returns one char at a time & assign to reverse
System.out.println("Reverse is :- "+reverse); //print reverse of string
}
}
Code to reverse string is as follows -
public class StringReverse {
public static void main(String[] args) {
String original, reverse =""; // declare two string variable
original = "Sample String"; //String to be reversed
int length = original.length(); //find length of string
for ( int i = length - 1 ; i >= 0 ; i-- )
reverse = reverse + original.charAt(i); //charAt returns one char at a time & assign to reverse
System.out.println("Reverse is :- "+reverse); //print reverse of string
}
}