Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class ExtractLine
  5. {
  6. public static void main(String[] args)
  7. {
  8. Scanner stdIn = new Scanner(System.in);
  9. String songs =
  10. "1. Bow Wow - Fresh Azimiz\n" +
  11. "2. Weezer - Beverly Hills\n" +
  12. "3. Dave Mathews Band - Crash Into Me\n" +
  13. "4. Sheryl Crow - Leaving Las Vegas\n";
  14.  
  15. String songNum; // song number that is searched for
  16. int songIndex; // position of where song number is found
  17. int eolIndex; // position of end of line character
  18. String song; // the specified line
  19.  
  20. System.out.print("Enter song number: ");
  21. songNum = stdIn.nextLine();
  22.  
  23. songIndex = songs.indexOf(songNum);
  24. ////////////// enter text here
  25. eolIndex = songs.indexOf("");
  26. System.out.println(songs.substring(songIndex,eolIndex-1));
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. } // end main
  34. } // end class ExtractLine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement