Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 2
What is equivalent of getch() in java?
7 Respostas
+ 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