String line = JOptionPane.showInputDialog("Enter a full name and surname").toUpperCase();
Scanner l = new Scanner (line);
int index = line.lastIndexOf(" ");
while (l.hasNext())
{
String name = l.next();
char ch = name.charAt(0);
System.out.print(ch);
}
System.out.print(" " + line.substring(index + 1));
Example:
User enters the following - Fred John Samuel Smith
The output should be - FJS SMITH
The code doesn't work because the output is this:
FJSS SMITH
How do I split the first 3 words from the last word?