Hey guys i seriously need this done as it is one of my extra credits and I can p
ID: 3533139 • Letter: H
Question
Hey guys i seriously need this done as it is one of my extra credits and I can pass only if this gets done. Pls help me and when you answer, please keep in mind the requirements below.
Write a Java program that reads a string of characters as input from user and prints the reverse of the string.
Specific requirements:
1. The program uses a recursive method.
2. You may not assume the maximum length of an input string.
3. You may not use strings, arrays or structured data types. You may use only one char variable in the method you define so that the program reads one character at a time.
4. The run of the program should looks like:
Input String: abcdefg
Its Reverse: gfedcba
Explanation / Answer
hope it's not to late to be rated
import java.util.*;
public class recursiveReverse
{public static void main(String [] args)
{String input;
Scanner in=new Scanner(System.in);
System.out.print("Enter a string: " );
input=in.nextLine();
System.out.println("Reversed: "+Reverse(input));
}
public static String Reverse(String s)
{if(s.length()==0)
return "";
else
return s.charAt(s.length()-1)+Reverse(s.substring(0,s.length()-1));
}
}