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

Write a statement that calls the recursive method backwardsAlphabet() with param

ID: 3663201 • Letter: W

Question

Write a statement that calls the recursive method backwardsAlphabet() with parameter startingLetter.

public class RecursiveCalls {
   public static void backwardsAlphabet(char currLetter) {
      if (currLetter == 'a') {
         System.out.println(currLetter);
      }
      else {
         System.out.print(currLetter + " ");
         backwardsAlphabet(--currLetter);
      }
      return;
   }

   public static void main (String [] args) {
      char startingLetter = '-';

      startingLetter = 'z';

      BackwardsAlphabet(startingLetter);

      return;
   }
}

Explanation / Answer

As per given problem statement updated the below given source code to print the recursively from alphabet 'z' to 'a' by calling method backwardsAlphabet in main method..

1. Here Modifications are updated starting char from z to a ..
2. print the result after calling the method backwardsAlphabet method.

See the below code :

public class RecursiveCalls
{
   public static void backwardsAlphabet(char ch)
   {
       if(ch=='z')
       {
           System.out.print("z ");
       }
       else
       {          
           backwardsAlphabet((char) (ch+1));
           System.out.print(ch+" ");
       }

   }

   public static void main (String [] args)
   {
       char startingLetter = '-';
       startingLetter = 'a';
       new RecursiveCalls().backwardsAlphabet(startingLetter);    
   }
}

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