Untitled

 avatar
unknown
plain_text
3 years ago
898 B
4
Indexable
import java.util.*;  // for Scanner

public class ProcessName2 {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        
        // Declare variables;
        System.out.print("Type your name: ");
        String input = console.nextLine();

        int spaceIndex = input.indexOf(" ");
        String lastName = input.substring(spaceIndex + 1);
        char firstInitial = input.charAt(0);
        int minChar = 6;
        
        // read the entire input as a single line

        while (input.length() <= minChar || !input.contains(" ")) {
            System.out.println("Error, must be at least 5 chars with a space.");
            System.out.print("Type your name: ");
            input = console.nextLine();
        }

        String name = lastName + ", " + firstInitial + ".";
        System.out.println("Your name is: " + name);
    
    }
}
Editor is loading...