java.util.scanner

Scanner input - end of input stream indicator

那年仲夏 提交于 2021-02-19 08:21:23
问题 I want to do the following : Read numbers into a stack; Read out numbers from stack one by one; Find square root for each number and print result //need a stack class import java.util.Iterator; import java.util.Stack; import java.io.*; import java.util.*; import java.lang.Math; public class Root { public static void main (String[] args) { Scanner inscan = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); Stack<Integer> stk = new Stack<Integer>(); //Iterator iterate = stk

Scanner input - end of input stream indicator

守給你的承諾、 提交于 2021-02-19 08:21:22
问题 I want to do the following : Read numbers into a stack; Read out numbers from stack one by one; Find square root for each number and print result //need a stack class import java.util.Iterator; import java.util.Stack; import java.io.*; import java.util.*; import java.lang.Math; public class Root { public static void main (String[] args) { Scanner inscan = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); Stack<Integer> stk = new Stack<Integer>(); //Iterator iterate = stk

Recognize arrow keys in Java Scanner or Console application

送分小仙女□ 提交于 2021-02-18 02:48:38
问题 I am writing a Java application that uses both Scanner and Console to get input from the user. I would like to add command history support so that the user can use the ARROW KEYS to search previous inputs (similar to a terminal). Is there a way to do this? Right now, when I use either the Scanner or the Console , I get weird symbols like ^[[A when pressing the arrow keys. I have read about KeyListener and KeyEvent , but my application does not use a GUI. Thanks! 回答1: Good question - +1'd. On

Recognize arrow keys in Java Scanner or Console application

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-18 02:45:08
问题 I am writing a Java application that uses both Scanner and Console to get input from the user. I would like to add command history support so that the user can use the ARROW KEYS to search previous inputs (similar to a terminal). Is there a way to do this? Right now, when I use either the Scanner or the Console , I get weird symbols like ^[[A when pressing the arrow keys. I have read about KeyListener and KeyEvent , but my application does not use a GUI. Thanks! 回答1: Good question - +1'd. On

returning string containing char c in scanner

我是研究僧i 提交于 2021-02-17 03:16:24
问题 Trying to create a method findNewLineWithChar() which returns a String and accepts a Scanner scn and a char c . It returns the line of the scanner which contains c . I've tried using a string to store the value of currentLine, but it seemed to convolute my code and not provide any answers anyways. I would love to use a String[], but I get a NullPointerException. What am I exactly doing wrong? public static String findLineWithChar(Scanner scn, char c) { /* * findLineWithChar returns line in

Ignoring characters using Scanner in Java

三世轮回 提交于 2021-02-10 22:16:58
问题 I want to take a multiple coordinate points, say (35,-21) (55,12)... from standard input and put them into respective arrays. Let's call them x[] and y[]. x[] would contain {35, 55, ...} and y[] would contain {-21, 12, ...} and so forth. However, I can't seem to find a way to get around the parenthesis and commas. In c I was using the following: for(i = 0; i < SIZE; i++) { scanf("%*c%d%*c%d%*c%*c",&x[i],&y[i]); } However in Java I can not seem to find a way to get around the non-numeric

Ignoring characters using Scanner in Java

妖精的绣舞 提交于 2021-02-10 22:10:27
问题 I want to take a multiple coordinate points, say (35,-21) (55,12)... from standard input and put them into respective arrays. Let's call them x[] and y[]. x[] would contain {35, 55, ...} and y[] would contain {-21, 12, ...} and so forth. However, I can't seem to find a way to get around the parenthesis and commas. In c I was using the following: for(i = 0; i < SIZE; i++) { scanf("%*c%d%*c%d%*c%*c",&x[i],&y[i]); } However in Java I can not seem to find a way to get around the non-numeric

while (!scannerObject.hasNext(patternObject)) works for only one iteration

喜你入骨 提交于 2021-02-10 16:09:36
问题 The problem I only get one successful iteration from a while loop that is controlled by a hasNext(Pattern pattern) condition. I try to 'clear' the input stream (?) with .next() but unsuccessfully. The behaviour If I enter invalid input the first time, seemingly valid subsequent input continues to execute the System.out.print("You did not enter a valid size. Try again: ") line. But this line should only execute if Scanner getPizzaSize does not have valid input. If instead I enter valid input

while (!scannerObject.hasNext(patternObject)) works for only one iteration

China☆狼群 提交于 2021-02-10 16:08:37
问题 The problem I only get one successful iteration from a while loop that is controlled by a hasNext(Pattern pattern) condition. I try to 'clear' the input stream (?) with .next() but unsuccessfully. The behaviour If I enter invalid input the first time, seemingly valid subsequent input continues to execute the System.out.print("You did not enter a valid size. Try again: ") line. But this line should only execute if Scanner getPizzaSize does not have valid input. If instead I enter valid input

while (!scannerObject.hasNext(patternObject)) works for only one iteration

痴心易碎 提交于 2021-02-10 16:08:13
问题 The problem I only get one successful iteration from a while loop that is controlled by a hasNext(Pattern pattern) condition. I try to 'clear' the input stream (?) with .next() but unsuccessfully. The behaviour If I enter invalid input the first time, seemingly valid subsequent input continues to execute the System.out.print("You did not enter a valid size. Try again: ") line. But this line should only execute if Scanner getPizzaSize does not have valid input. If instead I enter valid input