Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 1.1 Start with the code below and complete the getInt method. The method should prompt the user to enter an integer. Scan the input

Lab 1.1

Start with the code below and complete the getInt method. The method should prompt the user to enter an integer. Scan the input the user types. If the input is not an int, throw an IllegalArgumentException; otherwise, return the int.

import java.util.Scanner; public class Throwing { public static void main(String[] args) { int x = getInt(); System.out.println(x); } public static int getInt() { // your code goes here } } 

Lab 1.2

Modify the program from Lab 1.1 so that getInt throws an IOException instead of an IllegalArgumentException. Modify the main program so that it catches and prints the IOException.

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

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

How many three-digit numbers are divisible by 7?

Answered: 1 week ago

Question

What is Indian Polity and Governance ?

Answered: 1 week ago

Question

2. Discuss various aspects of the training design process.

Answered: 1 week ago