Java: How to get input from System.console()

后端 未结 9 1826
时光说笑
时光说笑 2020-11-22 09:08

I am trying to use Console class to get input from user but a null object is returned when I call System.console(). Do I have to change anything before using Sy

9条回答
  •  滥情空心
    2020-11-22 09:59

    Try this. hope this will help.

        String cls0;
        String cls1;
    
        Scanner in = new Scanner(System.in);  
        System.out.println("Enter a string");  
        cls0 = in.nextLine();  
    
        System.out.println("Enter a string");  
        cls1 = in.nextLine(); 
    

提交回复
热议问题