Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ReverseLetters {
- public static String reverse(String r) {
- String temp = null;
- if (r.length() == 1) {
- return r;
- }
- else {
- String right = r.substring(r.length()-1,r.length());
- String left = r.substring(0, r.length() -1);
- temp = right + reverse(left);
- return temp;
- }
- }
- public static void main(String[] args) {
- Scanner kb = new Scanner(System.in);
- System.out.print("Enter a string to be reversed: ");
- String input = kb.next();
- System.out.println(reverse(input));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement