// CSE 142, Autumn 2009, Marty Stepp // This program prompts the user for his/her name and converts it into a // "gangsta" version. The program demonstrates String methods. import java.util.*; public class GangstaName { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("Type your name, playa: "); String name = console.nextLine(); // first initial String firstInitial = name.substring(0, 1); // last name (caps) // index 01234567890 last index = 10 (.length() - 1) // name = "Marty Stepp" length = 11 int space = name.indexOf(" "); // 5 String lastName = name.substring(space + 1, name.length()); // or name.substring(space + 1); lastName = lastName.toUpperCase(); String firstName = name.substring(0, space); System.out.println("Your gangsta name is " + firstInitial + ". Diddy " + lastName + " " + firstName + "-izzle"); } }