Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose you have a file of population data of cities in Newfoundland and Labrado

ID: 3727735 • Letter: S

Question

Suppose you have a file of population data of cities in Newfoundland and Labrador, like: st. John's 106172 Mount Pearl 24284 Corner Brook 19886 Marystown 5506 Happy Valley-Goose Bay 7552 rou read the file with the following loop (assume all imports and declarations are okay) hile (scanner. hasNextl.ine o) city= scanner.nextLine() ; population= scanne r .next Int() ; //omitting code that works with population and city Given the example input file, this code is Your answer just fine O likely to raise an InputMismatchException O likely to raise a NumberformatException O likely to raise a NulPointerException 0 likely to raise an NoSuchElementException

Explanation / Answer

Given the Example input file the given code is :

Correct option:

Likely to raise an InputMismatchException

Explanation:

The while loop will read the file line by line. Now in first iteration the loop will check whether there exists the first line, it will satisfied and enter into the loop; then the first line is read by .nextLine() and next line is also read as an integer and return into population variable; after that when in 2nd iteration starts , it will try to check whether the next line exist or not, then it will enter the loop and the scanner object is now expecting an integer variable as in previous iteration it read an integer, but there is a string in the 3rd line so the input mismatch takes place here. Hence InputMismatchException will be there.

/*Hope this helps. Thanks.*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote