List of utility methods to do Scanner Read
String | readFromScanner(Scanner scanner) read From Scanner if (!scanner.hasNext()) { return new String(); return scanner.useDelimiter(REGEX_BEGINNING_OF_TEXT).next(); |
int | readInt(String prompt) Writes a prompt to standard out and tries to read an int value from standard in. int value = 0; boolean intRead = false; do { System.out.print(prompt); try (Scanner line = new Scanner(System.in); Scanner scannerLine = new Scanner(line.nextLine());) { if (scannerLine.hasNextInt()) { intRead = true; value = scannerLine.nextInt(); ... |
String | readLine(String format, Object... args) read Line System.out.print(String.format(format, args)); return new Scanner(System.in).nextLine(); |
int[][] | readMatrix(Scanner in, int n) read Matrix int[][] matrix = new int[n][n]; for (int i = 0; i < n; i++) { matrix[i] = readArr(in, n); return matrix; |
char[] | readPassword(String format, Object... args) read Password if (System.console() != null) return System.console().readPassword(format, args); System.out.println("WARNING -> Console password input unsupported, password entry in insecure mode!"); return readLine(format, args).toCharArray(); |
int | readPositiveInt(String message, Scanner input) Read in a positive integer, which may come from a configuration file int value = Integer.parseInt(getNextInput(input)); if (value < 1) { throwException("Error. Illegal configuration parameter: " + message + ": " + value); return value; |
ArrayList | readSystemInToIntArrayList() read System In To Int Array List ArrayList<Integer> array = new ArrayList<Integer>(); Scanner sc = new Scanner(System.in); while (sc.hasNextInt()) { array.add(sc.nextInt()); sc.close(); return array; |
String | readWholeString(Scanner s) read Whole String return s.useDelimiter("\\A").hasNext() ? s.next() : ""; |