Answered step by step
Verified Expert Solution
Question
1 Approved Answer
JAVA A. Move the output statement inside the try block B. Assign a value inside the catch block C. All answers are correct D. Assign
JAVA
A. Move the output statement inside the try block
B. Assign a value inside the catch block
C. All answers are correct
D. Assign a value to x and y before the try block
import java.util.Scanner; public class Add Numbers public static void main(String[] args) { int x,y; Scanner input = new Scanner(System.in); try { System.out.println("Enter an integer for x: "); x = input.nextInt(); System.out.println("Enter an integer for y: "); y = input.nextInt(); } catch(Exception badNumber) { System.out.println("Exception occurred"); } System.out.println("x is " + x); System.out.println("y is " + y); } } When this code runs, it will produce an error. How can this code be corrected to keep from getting the errorStep 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