Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ExtractLine
- {
- public static void main(String[] args)
- {
- Scanner stdIn = new Scanner(System.in);
- String songs =
- "1. Bow Wow - Fresh Azimiz\n" +
- "2. Weezer - Beverly Hills\n" +
- "3. Dave Mathews Band - Crash Into Me\n" +
- "4. Sheryl Crow - Leaving Las Vegas\n";
- String songNum; // song number that is searched for
- int songIndex; // position of where song number is found
- int eolIndex; // position of end of line character
- String song; // the specified line
- System.out.print("Enter song number: ");
- songNum = stdIn.nextLine();
- songIndex = songs.indexOf(songNum);
- ////////////// enter text here
- eolIndex = songs.indexOf("");
- System.out.println(songs.substring(songIndex,eolIndex-1));
- } // end main
- } // end class ExtractLine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement