Reverse String
807600Jun 25 2007 — edited Sep 25 2007Hi
I am very new to java and i am trying to reverse a string of text, the coe below works perfectly but i need the text to be input at the command prompt window and then it shows the output fo the reversed text as opposed tothe way i have set the code up below. does that make sense??
I basically need to have a line that says please enter your text to be reversed:
and it then reverses.
Thanks
public class TestStringReverse {
public static void main(String[] args) {
String string = "Enter string to be reversed";
String reverse = "";
int len = string.length();
if(len == 1) {
reverse = string;
} else {
for(int count = string.length()-1; count >= 0; count-- ) {
reverse += string.charAt(count);
}
}
System.out.println(reverse);