import java.util.*;
public class Initials
{
public static void main (String [] args)
{
Scanner keyboard = new Scanner (System.in);
String name;
System.out.println("Please enter your full name including your middle name: ");
name = keyboard.nextLine();
System.out.println(" ");
int x = name.indexOf(' ')+1;
String nameTwo = name.substring(x,name.length());
int y = nameTwo.indexOf(' ')+1;
System.out.println(name +" , your initials maybe this: " + name.charAt(0) + name.charAt(x) + name.charAt(y));
}
}
this is what i have and this is what it is supposed to do but it prints out the second intial twice.. where did i go wrong
Write a program that inputs a user’s full name with spaces between the first, middle,
and last names. The program should output the user’s initials. You may not use any
looping structure in this program. Hint you can do this quite easily with the String
method indexOf(). Save the program as Initials.java. Good luck.
Test Data
Input your name with one space between each name: John Quincy Adams
John Quincy Adam, your initials are: JQA
Input your name with one space between each name: Vicki Renee Williams
Vicki Renee Williams, your initials are: VRW
Input your name with one space between each name: Elvis Aaron Presley
Elvis Aaron Presley, your initials are: EAP