Answered step by step
Verified Expert Solution
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started