Help help Design a Java project with 2 methods main and recu

Help help

Design a Java project with 2 methods: main() and recursive method printString(). The main() method should ask the user to input a string and then call printString() method. The printString() method should output the string forwards and backwards and put a space in between. For example, if the input string is \"abc\", then invocation of your printString() method should produce the following output: \"abc cba\". The method printString() must be inplemented as recursive and called only once from main() to print both: the original string and its reverse. In your implementation of the printString() method you are not allowed to use any methods of Java API class String besides of chatAt() and length(). The output of the string and its reverse must be done on character-by-characted basis.

Solution

Hi, Please find my code.

Plese let me know in case of any issue.

public class Hw4_4 {

  

// function take index=0(index of first character in string) and string

   public static void printString(int index ,String str){

      

       // base case, when we hit length(end of string ), then print space

       if(index == str.length()){

           System.out.print(\" \");

           return;

       }

      

       // print current character

       System.out.print(str.charAt(index));

      

       // call recursively for next characters

       printString(index+1, str);

      

       // print character while returning(reverse order)

       System.out.print(str.charAt(index));

   }

  

   public static void main(String[] args) {

      

       printString(0, \"abc\");

   }

}

/*

sample run:

abc cba

*/

Help help Design a Java project with 2 methods: main() and recursive method printString(). The main() method should ask the user to input a string and then call
Help help Design a Java project with 2 methods: main() and recursive method printString(). The main() method should ask the user to input a string and then call

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site