Can it be cleaner? or improved?
sweetphilly2 (0)

Repl: https://repl.it/join/ivqffjsn-sweetphilly2

Hello,

Two things I'm looking for help with:

  • I'm looking for a better way to take in a line of text (in my code's case, some song information). I want the user to be able to type in one line of information; currently, the user has to type in two lines of information (i.e. track number then song title). For example, the user should be able to type in "1 Dream On" or "1. Dream On"
  • A better way to break the loop without using a keyword or phrase. Since the title of a song could be practically any name, I can't use that input as a way to break the loop. For instance, with the loop break depending on the user inputting "done", this disallows song title's from being set to "done".
You are viewing a single comment. View All
Answered by malvoliothegood (709) [earned 5 cycles]
View Answer
sweetphilly2 (0)

@malvoliothegood Okay. Thanks for the input once again.
I did something different. I used a regular expression within parseInt().
int track = Integer.parseInt(inputs[0].replaceAll("[\\D]", ""));
Do you see any issues with this? (Code is updated with this in there.)
I did not think about the possibility of a user entering a number with that representation...not sure if it's completely necessary for the code to handle that or not.