Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is my JAVA class assignment. Please help me to solve my Java question consi

ID: 3770894 • Letter: T

Question

This is my JAVA class assignment.

Please help me to solve my Java question consisting 3 parts.

A.Write a method that accepts a (any) string as an argument, the method should use recursion to display each individual character in the string.

B. Modify the method you just wrote(in part A) so it displays the String backwards.

C. What is the main difference in using a recurive algorithm for type of problem instead of using a iterative algorithm? (Answer as short as possible,dont want a long paragraph)

Thank you.

Explanation / Answer

Complete Program:

// File: MethodsTest.java
import java.util.*;
public class MethodsTest
{
public static void main(String[] args)
{  
  String str = "WELCOME";

  System.out.println("String value: " + str);
  
  System.out.println(" Individual character in forward order:");
  printForward(str, 0);
  
  System.out.println(" Individual character in backword order:");
  printBackword(str, 0);
}

public static void printForward(String str, int pos)
{
  if(pos < str.length())
  {
   System.out.println(str.charAt(pos));
   printForward(str, pos + 1);
  }  
}

public static void printBackword(String str, int pos)
{
  if(pos < str.length())
  {
   printBackword(str, pos + 1);
   System.out.println(str.charAt(pos));
  }
}
}


Sample Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote