Question
3. What is the output of the program below, state if there will be an exception? If so, state what type is it, and show
3. What is the output of the program below, state if there will be an exception? If so, state what type is it, and show how to handle it. class Class1 { public static void main(String args[]) { int total = 0; int[] i = new int[3]; for(int j=1;j<= i.length; j++) total += (i[j] = j); System.out.println(total); } } 4. What is the output of the program below: try { int values[] = {1,2,3,4,3,2,1}; for (int i = values.length-1; i >= 0; i++) System.out.print( values[i] + " " ); } catch (Exception e) { System.out.print("2" + " "); } finally { System.out.print("3" + " "); }
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