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

JAVA A. Move the output statement inside the try block B. Assign

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 error

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!