java - When I pressed enter as an input, my program does not print anything -


import java.util.nosuchelementexception; import java.util.scanner; public class test4 {    public static void main(string[] args) {       scanner scanner = new scanner(system.in);       string name = "name";       int low = 0;       int high = 0;       int count = 0;       double dnum = 0.0;        while(name!=null) {          try {             if (scanner.hasnextline()) {                if (scanner.hasnextint()) {                   low = scanner.nextint();                   high = scanner.nextint();                   count = scanner.nextint();                   name = null;                } else if (scanner.hasnextdouble()) {                   dnum = scanner.nextdouble();                   system.out.print(dnum + " not integer");                   name = null;                } else {                   system.out.print("user enter enter");                   name = null;                }             }          } catch (nosuchelementexception e) {             system.out.print(dnum + "is not integer");             name=null;             system.out.print(low);             system.out.print(high);          }       }    scanner.close();     } } 

when pressed enter input, program not print anything. if replace new scanner(system.in) new scanner("\n"), program work expected. can explain me?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -