Question: Consider the flawed method printLetters that follows, which accepts a String as its parameter and attempts to print the letters of the String , separated
Consider the flawed method printLetters that follows, which accepts a String as its parameter and attempts to print the letters of the String , separated by dashes. For example, the call of printLetters("Rabbit") should print R-a-b-b-i-t . The following code is incorrect:

What is wrong with the code? How can it be corrected to produce the desired behavior?
public static void printLetters (String text) { for (int i = 0; i < text.length (); i++) { !! System.out.print (text.charAt (i) + "-"); } System.out.println (); // to end the line of output
Step by Step Solution
3.37 Rating (166 Votes )
There are 3 Steps involved in it
The printLetters code has a fencepost problem it will print a das... View full answer
Get step-by-step solutions from verified subject matter experts
