import java.util.Scanner;
class StringReverse{
public static void main (String[] args){
Scanner s = new Scanner (System.in);
System.out.println("Enter text to reverse: ");
String st = s.nextLine();
reverse(st);
}
public static void reverse(String s){
if (s.length() == 1){
System.out.print(s);
}
else{
reverse (s.substring(1, s.length()));
System.out.print(s.substring(0,1));
}
}
}
No comments:
Post a Comment