import java.util.Scanner; public class SplitName { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Please enter a name: "); String name = in.nextLine().trim(); in.close(); int index = name.indexOf(" "); if (index < 0) { System.err.println("Name must be in the form of \"firste last\""); System.exit(1); } String firstName = name.substring(0, index); String lastName = name.substring(index).trim(); System.out.println("First Name: " + firstName); System.out.println("Last Name: " + lastName); } }