Is there any getch() equivalent in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Is there any getch() equivalent in java?

5th Mar 2017, 5:20 AM
Ramachandra Reddy
Ramachandra Reddy - avatar
2 Answers
+ 13
You may try the following way: Scanner in = new Scanner (System.in); char a = in.next(); If you're referring to any character which is not supposed to be saved as a variable, then you may use the following : in.next(); // it'll consume the extra character
18th Mar 2017, 9:54 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 3
Use new Scanner(System.in) with out any variable That's all Example of I mean: public class ILikeCow{ public static void main(String[] ouch){ java.lang.System.out.print("...."); //I like to use java.lang.System =-= new java.util.Scanner(java.lang.System.in); java.lang.System.out.print("I prefer cow than java.lang.System"); //This getch() is certainly not working in code playground //If this thing compile with error then I'm srry } }
5th Mar 2017, 5:21 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar