Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that takes in three integers as inputs and outputs the largest value. Use a try block to perform all the statements. Use

Write a program that takes in three integers as inputs and outputs the largest value. Use a try block to perform all the statements. Use a
catch block to catch any NoSuchElementException caused by missing inputs. Then output the number of inputs read and the largest value,
or output "No max" if no inputs are read.
Note: Because inputs are pre-entered when running a program in the zyLabs environment, the system throws the NoSuchElementException
when inputs are missing. Test the program by running the program in the Develop mode.
Hint: Use a counter to keep track of the number of inputs read and compare the inputs accordingly in the catch block when an exception is
caught.
Ex: If the input is:
75
the output is:
7
Ex: If the input is:
3
the system throws the NoSuchElementException and outputs:
1 input (3) read:
Max is3
Ex: If no inputs are entered:
the system throws the NoSuchElementException and outputs:
O input(s) read:
No max
LAB
ACTIVITY
10.12.1: LAB: Input errors with zyLabs
010
LabProgram.java
Load default template...
import java.util.scanner;
import java.util. NoSuchElementException;
public class LabProgram {
public static void main(String[] args){
Scanner scnr = new Scanner(
System.in);
int val1;
int val2;
int val3;
int max;
vall =0;
val2=0;
val 3=0;
/* Type your code here. */
}
}
(JAVA PLEASE! THE OUTPUT NEEDS TO BE LIKE THE OUTPUT THAT IS IN THE PICTURE THAT IS ATTACHED.)
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_2

Step: 3

blur-text-image_3

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

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions