+ 2

Is there a way to get input of a single chracter without the need of pressing Enter key or Return key in JAVA Programming

Something similar to getchar() in C Programming

30th Jun 2020, 2:51 PM
K. MASTREX
K. MASTREX - avatar
6 Respostas
+ 2
No, I don't think that there exist such a solution. At least not with console codes.
1st Jul 2020, 8:41 AM
Denise Roßberg
Denise Roßberg - avatar
+ 1
System.in can be used at InputStream somehow, ok, I'll look it up... Okay, there is a way and I cannot post the solution here. Just search for the keywords "Java raw mode console" and you'll find it...
1st Jul 2020, 3:18 PM
Sandra Meyer
Sandra Meyer - avatar
0
You could use the BufferedReader and InputStream, there's a way... Haven't done that for a long time...
30th Jun 2020, 4:36 PM
Sandra Meyer
Sandra Meyer - avatar
0
getchar() in C accepts buffered input. You're probably thinking of getch() which is not part of standard C. Maybe there's some 3rd party library out there that handles unbuffered input, but I don't think Java supports it out of the box.
30th Jun 2020, 7:50 PM
Gen2oo
Gen2oo - avatar
0
Hello K. MASTREX Using Scanner: Scanner scan = new Scanner(System.in); char input = scan.next().charAt(0); You can also look here: https://stackoverflow.com/questions/13942701/take-a-char-input-from-the-scanner
30th Jun 2020, 8:05 PM
Denise Roßberg
Denise Roßberg - avatar
0
I read that too, Denise Its like extracting the first chracter from the whole line input and you have to press Enter key. From the above question I meant that, just like in getchar input is read as soon as user presses any character key and there is no need of another return key for submission.
1st Jul 2020, 6:05 AM
K. MASTREX
K. MASTREX - avatar