Hello Everyone I am writing simple program that accepts user inputs with java Scanner class from the java.util package. But when I click the console to type something it is not accepting the keyboards input(it does not show the keyboard inputs) , what’s wrong with the console? or the IDE itself ? any solution please
import java.util.Scanner; // import the Scanner class
class Main {
public static void main(String[] args) {
Scanner myObj = new Scanner(System.in);
String userName;
// Enter username and press Enter
System.out.println("Enter username");
userName = myObj.nextLine();
System.out.println("Username is: " + userName);
}
}
>Solution :
It may be an issue with the IDE or the console itself. You can try running the program in a different IDE or in the command line to see if the issue persists.
Alternatively, you can try using the System.console() method to retrieve the console input stream directly, like this:
Scanner myObj = new Scanner(System.console().reader());
This should also allow the Scanner to properly read input from the console.
[the console](https://i.stack.imgur.com/JP89p.png)](https://i0.wp.com/i.stack.imgur.com/HECtn.png?w=1200&ssl=1)