Question: 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

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!