Consider the flawed method printLetters that follows, which accepts a String as its parameter and attempts to

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 by dashes. For example, the call of printLetters("Rabbit") should print R-a-b-b-i-t . The following code is incorrect:

public static void printLetters (String text) { for (int i = 0; i < text.length (); i++) { !! System.out.print (text.charAt (i) +

What is wrong with the code? How can it be corrected to produce the desired behavior?

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Building Java Programs A Back To Basics Approach

ISBN: 9780135471944

5th Edition

Authors: Stuart Reges, Marty Stepp

Question Posted: