I am not sure why the loop doesn't work? I keep getting an error. It works the first time around but after that, it says that it's out of bounds? Please help, I'm confused.
public static void main(String[]args) {
Scanner user = new Scanner(System.in);
boolean yn = true;
char choice;
while (yn) {
System.out.println("Please enter your first name and last name, separated by a space.");
    String name=user.nextLine();
        name = name.trim();
        int r = name.indexOf(" ");
        String first = name.substring(0,r);
        String last = name.substring(r+1);
        int lengthlast = last.length();
System.out.println("Hello there " + first + " I have your first name as " +  first + ", which has " + r + " characters.");
System.out.println("Hello again " + first + " I have your last name as " + last + ", which has " + lengthlast + " characters.");
    String firstinit = name.substring(0,1);
        firstinit = firstinit.toUpperCase();
    String lastinit = name.substring(r+1,r+2);
        lastinit = lastinit.toUpperCase();
System.out.println("Did you know that your initials are " + firstinit + "" + lastinit);
System.out.println("Do you wish to continue? (Y)yes or (N)no ?");
    choice = user.next().charAt(0);
        switch (choice) {
            case 'y':
                yn=true;
                break;
            case 'Y':
                yn=true;
                break;
            case 'n':
                yn=false;
                break;
            case 'N':
                yn=false;
    }
}
}
 
    