Scan first and last name from user, then format the name as last, first initial
Methods

I'm assuming this chunk of code sits in your main() method, and I think one quick way of improving it is to break it into two methods - one that returns a validated user input (at least 5 chars with a space), and one for the actual work.

When you separate them, you will also realize that you only need to print your validation message once, instead of twice as you are doing currently (to check for length, and to check for a space).

Stricter input validation


  Type your name: Jessica Miller 
  
  Your name is: Miller, J.


Since you actually require the initial of the first name, you also need to check that the space is not at the start or the end of the input, as otherwise you only have one name. Consider this:

private static void test(String input) {
    // A Scanner works in a similar way to the legacy StringTokenizer class
    try (Scanner scanner = new Scanner(input)) {
        while (scanner.hasNext()) {
            System.out.printf("Token: [%s]%n", scanner.next());
        }
    }
}

test("hello world");
// Token: [hello]
// Token: [world]

test(" helloworld");
// Token: [helloworld]

test("helloworld ");
// Token: [helloworld]


An example implementation to validate for this can be:

private static final int REQUIRED_LENGTH = 5;

private static String getInput(Scanner scanner) {
    String result = scanner.nextLine();
    while (result.length() &lt; REQUIRED_LENGTH ||
            !result.contains(" ") ||
            result.startsWith(" ") ||
            result.endsWith(" ")) {
        System.out.println("Try again.");
        result = scanner.nextLine();
    }
    return result;
}


Still, this can be defeated if there are multiple spaces and they happen to also be at the start and/or the end. Perhaps a regex solution may be better here... this shall be left as an exercise for the reader.

Boolean flags

Going back to your main() method, you wouldn't require correctName if you have separated the logic that validates the user input and the actual work.