5 Replies - 165 Views - Last Post: 07 July 2019 - 11:08 PM Rate Topic: -----

#1 UserKunal123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-July 19

Scanner class: nextInt() function

Posted 07 July 2019 - 07:37 AM

When we use Scanner class to take input during program runtime, is it that, first the nextInt() is called THEN we give the input, OR
after we give the input THEN the nextInt() function is called?
Is This A Good Question/Topic? 0
  • +

Replies To: Scanner class: nextInt() function

#2 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3639
  • View blog
  • Posts: 16,720
  • Joined: 20-September 08

Re: Scanner class: nextInt() function

Posted 07 July 2019 - 07:45 AM

Why not look at the API docs? https://docs.oracle....ml#hasNextInt--
Was This Post Helpful? 0
  • +
  • -

#3 UserKunal123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-July 19

Re: Scanner class: nextInt() function

Posted 07 July 2019 - 07:54 AM

View Postg00se, on 07 July 2019 - 07:45 AM, said:

Why not look at the API docs? https://docs.oracle....ml#hasNextInt--


I have read the docs, but I couldn't find any answer to my problem there.
Was This Post Helpful? 0
  • +
  • -

#4 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3639
  • View blog
  • Posts: 16,720
  • Joined: 20-September 08

Re: Scanner class: nextInt() function

Posted 07 July 2019 - 08:17 AM

"Returns true if the next token in this scanner's input can be interpreted as an int value in the default radix"
so there must be a token already there, before the method is called, mustn't there?
Was This Post Helpful? 0
  • +
  • -

#5 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 780
  • View blog
  • Posts: 5,869
  • Joined: 25-December 13

Re: Scanner class: nextInt() function

Posted 07 July 2019 - 09:11 AM

I would think the program could call nextInt at any time, both before and after the user enters some data. The method would not return until after it has data to look at.
The doc for hasNext says:

Quote

This method may block while waiting for input to scan.

This post has been edited by NormR: 07 July 2019 - 09:14 AM

Was This Post Helpful? 1
  • +
  • -

#6 wseng92   User is offline

  • D.I.C Addict
  • member icon

Reputation: 50
  • View blog
  • Posts: 693
  • Joined: 23-September 15

Re: Scanner class: nextInt() function

Posted 07 July 2019 - 11:08 PM

Cross-post : Scanner class: next() function
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1