Write a program called NameGamejava that outputs The Name Ga
Write a program called NameGame.java that outputs \"The Name Game\" where the user inputs a first and last name and a song in the following format is printed about their first, then last name. Use a method to avoid redundancy. Here is a sample run of the program: What is your name? Fifty Cent Fifty Fifty, bo-Bifty Banana-fana fo-Fifty Fee-fi-mo-Mifty FIFTY!
Solution
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String fullname = sc.nextLine();
for(String name : fullname.split(\" \"))
{
printSong(name);
}
sc.close();
}
public static void printSong(final String name)
{
System.out.println(name + \" \" + name + \", bo-B\" + name.substring(1));
System.out.println(\"Banana-fana fo-F\" + name.substring(1));
System.out.println(\"Fee-fi-mo-M\" + name.substring(1));
System.out.println(name.toUpperCase() + \"!\");
}
}
