Created
February 24, 2022 19:39
-
-
Save Pzdrs/029edcee5f547bcd8c2320f0d927ab93 to your computer and use it in GitHub Desktop.
Prompt the user for a string until empty line is passed in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Prompt the user for a string until empty line is passed in | |
| * | |
| * @param consumer A consumer interface with a piece of code that is suppose to be ran on each iteration | |
| */ | |
| public static void readLineUntilEmpty(Consumer<String> consumer) { | |
| String line; | |
| do { | |
| System.out.print("Enter a string: "); | |
| line = Main.scanner.nextLine(); | |
| if (!line.isEmpty()) consumer.accept(line); | |
| } while (!line.equals("")); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment