+ 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
6 Réponses
+ 2
No, I don't think that there exist such a solution. At least not with console codes.
+ 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...
0
You could use the BufferedReader and InputStream, there's a way... Haven't done that for a long time...
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.
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
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.