Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

NetBeans IDE console does not work with user inputs (Java scanner class)

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);        
  }
}

[the program](https://i.stack.imgur.com/HECtn.png)[the console](https://i.stack.imgur.com/JP89p.png)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading