public class TextParsing { public static void main(String args[]) { String KK_OK = "KK OK:"; String KK_SETUP = "KK SETUP:"; String KK_PUNCH = "KK PUNCH:"; String line1 = "KK OK:8"; String line2 = "KK SETUP:Costa"; String line3 = "KK PUNCH:Costa lot"; // the String.length method returns the number of chars in a String // the String.substring(int i) method extracts all characters beginning // with the i-th one // the Integer.parseInt(String s) converts a String to int if possible, or // generates an optional NumberFormatException int numJokes = Integer.parseInt(line1.substring(KK_OK.length())); // generating a random int between 0 and numJokes-1: int i = (int)(numJokes*Math.random()); System.out.println("Number of Jokes: " + numJokes); System.out.println("Joke setup: " + line2.substring(KK_SETUP.length())); System.out.println("Joke punch line: " + line3.substring(KK_PUNCH.length())); } }