how to terminate the input when using . hasNext() in java?

Asked

Viewed 314 times

-2

I’m using a code that uses Scanner (I named after input) and uses while(input.hasNextLine()), but he keeps asking for input, I know he has a specific command for it (something like /n) but I can’t remember.

Could someone help me?

  • 2

    Present your code to see the problem.

1 answer

0


Hello you can do something like this:

Scanner ler = new Scanner(System.in);
//seu código de entrada
if (ler.equals("")) {
        ler.close();
    }   
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.