Question: Jump to level 1 The while loop reads values from input until two integers are read. Complete the exception hanc InputMismatchException exception and: Output Discarded

Jump to level 1
The while loop reads values from input until two integers are read. Complete the exception hanc InputMismatchException exception and:
Output "Discarded bad input value for postal ZIP code". End with a newline.
Discard the invalid input.
Ex: If the input is 394798847623196, then the output is:
Postal ZIP code is 39479
Postal ZIP code is 88476
Processed two valid input values
Ex. If the input is 39479 Q 88476,23196, then the output is:
Postal ZIP code is 39479
Discarded bad input value for postal ZIP code
Postal ZIP code is 88476
Processed two valid input values
Note: Each value read from input is on one line.
import java.util.Scanner;
import java.util. InputMismatchException;
public class TwoPostalZipCodes {
public static void main(String[] args){
Scanner scnr= new Scanner(
System.in);
int postalZipCode;
int validCount =0;
while (validCount 2){
try {
 Jump to level 1 The while loop reads values from input

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!