Write a program that asks the user to enter their first name and their last name, separated by a space. Break the input string up into two strings, one containing the first name and one containing the last name. You can do that by using the indexOf() subroutine to find the position of the space, and then using substring() to extract each of the two names. Also output the number of characters in each name and output the user’s initials. (The initials are the first letter of the first name together with the first letter of the last name.) A sample run of the program should look something like this: Please enter your first name and last name, separated by a space. ? Mary Smith Your first name is Mary, which has 4 characters Your last name is Smith, which has 5 characters Your initials are MS
Q1: Write a program that asks the user to enter their first name and their last name,
separated by a space. Break the input string up into two strings, one containing the
first name and one containing the last name. You can do that by using the indexOf()
subroutine to find the position of the space, and then using substring() to extract
each of the two names. Also output the number of characters in each name and
output the user’s initials. (The initials are the first letter of the first name together
with the first letter of the last name.) A sample run of the program should look
something like this:
Please enter your first name and last name, separated by
a space.
? Mary Smith
Your first name is Mary, which has 4 characters
Your last name is Smith, which has 5 characters
Your initials are MS
Step by step
Solved in 2 steps with 2 images