+ 2
What is equivalent of getch() in java?
7 odpowiedzi
+ 8
Use an extra nextLine as the following example :
Scanner scan = new Scanner (System.in);
int a = scan.nextInt();
scan.nextLine(); // serves as getch()
String str = scan.nextLine();
+ 4
@Thomas
Thank you, for the link and explanation!
+ 3
API says it
Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
https://docs.oracle.com/javase/7/docs/api/
+ 2
getch() in c wait for user to press key. Will System.in.read() do the same job?
+ 1
Try System.in.read() this returns a int value. I don't know what getch() returns, but eather way convertion should not be the problem.
+ 1
bookmarked 💾
+ 1
@Manual your welcome