/** * The main method. * * @param args the command line arguments */ public static void main( String args[] ) { String str1; // The string entered by the user String output; String firstName; String middleName; String lastName; String phoneNumber; int indexOfFirst; int indexOfMiddle; int indexOfLast; int indexOfPhone; Scanner input = new Scanner( System.in ); // Read in the strings System.out.print( "Enter First Name, Middle Name, Last Name, and Phone Number: " ); str1 = input.nextLine(); System.out.println(); indexOfFirst = str1.indexOf(' '); indexOfMiddle = str1.indexOf(' ', indexOfFirst + 1); indexOfLast = str1.indexOf(' ', indexOfMiddle + 1); indexOfPhone = str1.indexOf(' ', indexOfLast + 1); firstName = str1.substring(0, indexOfFirst); middleName = str1.substring(indexOfFirst, indexOfMiddle); lastName = str1.substring(indexOfMiddle, indexOfLast); phoneNumber = str1.substring(indexOfLast); firstName = firstName.toLowerCase(); middleName = middleName.toLowerCase(); lastName = lastName.toLowerCase(); phoneNumber = phoneNumber.substring(phoneNumber.length() - 4); firstName = firstName.substring(0,1); middleName = middleName.substring(0,1); lastName = lastName.substring(0,1); output = firstName + middleName + lastName + phoneNumber; // Display the results System.out.println(output); } }