Created
July 26, 2020 13:24
-
-
Save nickname55/639dcf934c90da48b39ee13be0b3b944 to your computer and use it in GitHub Desktop.
как в командной строке java читать ввод пользователя
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
| import java.util.Scanner; | |
| public class Cmd { | |
| public static void main(String[] args) { | |
| System.out.println("для выхода введите exit"); | |
| Scanner scanner = new Scanner(System.in); | |
| String line = ""; | |
| line = readLine(scanner); | |
| while (!line.toLowerCase().equals("exit")) { | |
| line = readLine(scanner); | |
| } | |
| } | |
| private static String readLine(Scanner scanner) { | |
| String line = ""; | |
| if (scanner.hasNextLine()) { | |
| line = scanner.nextLine(); | |
| System.out.println(line); | |
| } | |
| return line; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment