Scanner Methods

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/4

encourage image

There's no tags or description

Looks like no tags are added yet.

5 Terms

1
New cards

nextLine()

skips first: nothing

consumes: everything to the end of the line, plus the \n

returns: rest of the current line, without the \n

cursor ends up: Start of the next line

throws if it fails: NoSuchElementException if no lines remain

2
New cards

next()

skips first: leading whitespace (spaces, tabs, newlines)

consumes: the next token, up until whitespace (spaces, tabs, newlines)

returns: next token as a String

cursor ends up: just after the token

throws if it fails: NoSuchElementException if no tokens remain

3
New cards

nextInt()

nextDouble()

nextBoolean()

skips first: leading whitespace (spaces, tabs, newlines)

consumes: the next token, up until whitespace (spaces, tabs, newlines)

returns: next token as an int, double, or boolean

cursor ends up: just after token

throws if it fails: InputMismatchException if the token is not an int/double/boolean. the bad token is not consumed. the cursor doesn’t move.


NoSuchElementException if no tokens reamin

4
New cards

hasNextLine()

true whenever any input remains, even a lone newline

5
New cards

hasNext()

  • skips leading whitespace js as next methods do; is false when only spaces and newlines remain

  • checks on token ahead; doesn’t scan whole output