So the question is how to change the output so that the first time \"Katie\" is
ID: 3784193 • Letter: S
Question
So the question is how to change the output so that the first time "Katie" is used it uses one exclamation point but the second time it uses 3.
Modify secondverse to play he Name Game (a.k.a. "The Banana Song see Wikipedia.org), by replacing "(Name) with userName but without the first letter. Ex: if userName Katie', the program prints: Banana-fana fo-fatie Note: The song verse may chang such as: Banana-fana fo-f(Name or Apple-fana fo-f(Name) 1 import java util Scanner 3 public class Name song 4 public static void main (String DJ args f(Nome String secondverse Banana-fana fo String userName Katie user Name userName substring(1) Removes first char from userName secondverse secondverse. replace Name) ""D; second verse userName System.out. rintlnC secondVerse 14 turn 17 Run v Testing Katie Your output: Banana-fana fo-fa tie v Testing Walter Banana-fana fo-falter Your output: Testing Katie and ending with instead of Expected output: Banana-fana fo-fa tie Your output Banana-fana fo atieExplanation / Answer
Hi Friend, There is small mistake in your code.
Please find my code and let me know in case of any issue.
public class NameSong {
public static void main(String[] args) {
String secondVerse = "Banana-fano fo-f(Name)!";
String userName = "Katie";
userName = userName.substring(1);
// replacing (Name) with userName
secondVerse = secondVerse.replace("(Name)", userName);
System.out.println(secondVerse);
return;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.