RECURSIVE METHOD (Java) Fill in the missing piece of code where /*Your Solution
ID: 3672816 • Letter: R
Question
RECURSIVE METHOD (Java)
Fill in the missing piece of code where /*Your Solution goes here*/ is written.
Here is the same code again:
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';
/* Your solution goes here */
return;
}
}
Explanation / Answer
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;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.