Modify songVerse to play "The Name Game" (see OxfordDictionaries), by replacing "(Name)" with userName but without the first letter. Ex: If userName = "Kaitlin" and songVerse = "Banana-fana fo-f(Name)!", the program prints: Banana-fana fo-faitlin! Ex: If userName = "Kaitlin" and songVerse = "Fee fi mo-m(Name)", the program prints: Fee fi mo-maitlin Note: You may assume songVerse will always contain the substring "(Name)".

Respuesta :

Answer:

Following are the modification of the code:

import java.util.*;//import package for user input

public class NameSong //defining NameSong  

{

   public static void main (String [] args) //defining the main method

   {

       String userName,songVerse;//defining string variable

       Scanner obxc = new Scanner(System.in);//creating Scanner class object

       userName = obxc.nextLine();//input string value

       songVerse = obxc.nextLine();//input string value

       userName = userName.substring(1); // Removes first char from userName

       songVerse = songVerse.replace("(Name)",userName);//remove and hold value in songVerse

       System.out.println(songVerse);//print value

   }

}

Output:

please find the attachment.

Explanation:

Description of the code:

  • In the above code, a two-string variable "userName and songVerse" is declared, in which we input value by creating scanner class object that is "obxc".
  • In the next step, two inbuilt string methods "substring and replace" are used, in which the first method is used to remove the first character from the name, and the second method replaces the value from the second input.  
  • At the last step, the print methods have used that prints its replaced value.
Ver imagen codiepienagoya

The code is in Python.

It modifies the strings using slicing and replace() method.

Slicing can be used when we want to get some part of the string. In this case, we use userName[1:]. This gives us all the string excluding the first character.

The replace() method takes two arguments. The first argument is replaced by the second one in the string.

Comments are used to explain each line of the code

The output is attached as an image

#get the inputs from the user

userName = input()

songVerse = input()

#remove the first character from the userName

userName = userName[1:]

#replace the (Name) with userName within the songVerse using replace() method

songVerse = songVerse.replace("(Name)", userName)

#print the songVerse

print(songVerse)

You may see another question at:

https://brainly.com/question/18722766

Ver imagen frknkrtrn
ACCESS MORE