Answer:
The program in Java is as follows:
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
char cont = 'Y';
while(cont == 'Y'){
System.out.print("Name: ");
String name =input.nextLine();
String names [] = name.split(" ");
names[0] = names[0].replaceAll("\\s", "");
names[1] = names[1].replaceAll("\\s", "");
System.out.println("Hello their "+names[0]+", I have your first name as "+names[0]+", which has "+names[0].length()+" characters ");
System.out.println("Hello again "+names[0]+", I have your last name as "+names[1]+", which has "+names[1].length()+" characters ");
System.out.println("Did you know that your initials are "+names[0].charAt(0)+names[1].charAt(0));
System.out.print("Continue (Y)Yes or (N)No: ");
cont = Character.toUpperCase(input.next().charAt(0));
input.nextLine();} }}
Step-by-step explanation:
This initializes a character variable cont to Y
char cont = 'Y';
This is repeated as long as cont is Y
while(cont == 'Y'){
This prompts the user for name
System.out.print("Name: ");
This gets the name from the user
String name =input.nextLine();
This splits the name into the array of two elements (first name and last name)
String names [] = name.split(" ");
This remove all whitespace from the first name
names[0] = names[0].replaceAll("\\s", "");
This remove all whitespace from the last name
names[1] = names[1].replaceAll("\\s", "");
This prints the details of the first name
System.out.println("Hello their "+names[0]+", I have your first name as "+names[0]+", which has "+names[0].length()+" characters ");
This prints the details of the last name
System.out.println("Hello again "+names[0]+", I have your last name as "+names[1]+", which has "+names[1].length()+" characters ");
This prints the initials
System.out.println("Did you know that your initials are "+names[0].charAt(0)+names[1].charAt(0));
This prompts the user to continue or not
System.out.print("Continue (Y)Yes or (N)No: ");
This gets the user response
cont = Character.toUpperCase(input.next().charAt(0));
input.nextLine();} }