Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 {
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions