Problem 1 (try-catch blocks): Complete the program below in order to make run pr
ID: 3752579 • Letter: P
Question
Problem 1 (try-catch blocks): Complete the program below in order to make run properly package lab3exlwitherror import java.io. import java.util. public class Lab3Exlwitherror public static void main (String args) // do not change anything on this line Scanner readnew Scanner (System.in) String languages [ ] = {"Python", "Java", int a[] = {5, 0); Scanner input -nulli int number; int i, j "JavaScript", "Perl", "C", "C++"); // Exception 1 for (int í _ 0; ce languages. length; System.out.println (languages[i); //Exception 2 System.out-printin ("enter two integr value for i and j") i read.nextInt ) jread.nextInt i System.out.println("The result is :" ai / atl) // Eception3 inputnew Scanner (new FileReader "data.in")) while (input.hasNext ) number-input.nextInt System.out.println (number) input.close) // Eception4 Change 100 to 1000000000 long datanew long [1000000000Explanation / Answer
Problem 1: Modified code(problem 1) according to the program requirement
Note: Problem 2 image is not visible properly to answer.
package lab3ex1witherror;
import java.io.*;
import java.util.*;
public class Lab3Ex1witherror {
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
String languages[] = {"Python","Java","Java Script","Perl","C","C++"};
int a[] = {5, 0};
Scanner input = null;
int number;
int i, j;
try{
for(i=0;i<=languages.length;i++) {
System.out.println(languages[i]);
}
}catch(ArrayIndexOutOfBoundsException e) {
System.out.println(e);
}
try {
System.out.println("enter two integer value for i and j");
i=read.nextInt();
j=read.nextInt();
System.out.println("The result is :"+a[i]/a[j]);
}catch(ArithmeticException e) {
System.out.println(e);
}
try {
input = new Scanner(new FileReader("data.in"));
}catch (FileNotFoundException e) {
System.out.println(e);
}
try {
long data[] = new long[1000000000];
}catch(Error e) {
System.out.println(e);
}
}
}
Output:
Python
Java
Java Script
Perl
C
C++
java.lang.ArrayIndexOutOfBoundsException: 6
enter two integer value for i and j
1
0
The result is :0
java.io.FileNotFoundException: data.in (The system cannot find the file specified)
java.lang.OutOfMemoryError: Java heap space
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.