I have just started learning to write Java and I'm stumped already!
I have to write a short program that asks the user to type their name in full. The assumption is that their full name comprises of 3 names. The first initial of each name should then be displayed.
eg, 'Please enter your full name' ~: Flo The Minx
F T M
The tutorial that I am working from tells me to use the string methods to work out where the first and last spaces are.
Here is what I have so far... (I know it's wrong because the answer it displays is '123')
Also, I brief explanation of the answer would be appreciated as I am trying to learn and I won't learn without knowing how it works, thanks
public class Initials
public static void main (Stringargs)
//create Scanner to read from keyboard
Scanner myKeyboard = new Scanner(System.in);
//ask for name
System.out.print("Please enter your full name~: ");
String name = myKeyboard.nextLine();
System.out.print((name.charAt(0)) + (name.indexOf(' ') + 1));