0

I'm unable to run this code correctly.. Please help me out

public static void main(String[] args){     
     Console console = System.console();    // unable to fetch anything. It returns null
    if (console == null) {
        System.out.println("Unable to fetch console");
        return;
    }
    System.out.println("Enter your name: ");   //compiler doesn't come till here 
    String n=console.readLine();    
    System.out.println("Welcome "+n);   
}
  • 4
    Just so you know the `Console` is not the same as the command line. Maybe look at `System.in` and couple it with a `Scanner` instead – MadProgrammer Jun 15 '21 at 06:33
  • Actually, you are running it correctly, it's just that the behavior of the code doesn't match your expectations. As MadProgrammmer already said, use an instance of Scanner instead – Stultuske Jun 15 '21 at 06:36

0 Answers0