Aman jAVA
Aman jAVA
Aman Tomar
BCAN1CA22097
try {
System.out.println("Enter the number of elements in the array");
int n = Integer.parseInt(scanner.nextLine());
OUTPUT:
Enter the number of elements in the array
2
Enter the elements in the array
50
80
Enter the index of the array element you want to access
1
The array element at index 1 = 80
The array element successfully accessed
2). public class MathOperation {
public static void main(String[] args) {
try {
// Check if 5 arguments are provided
if (args.length != 5) {
throw new IllegalArgumentException("Exactly 5 integers are required.");
}
} catch (NumberFormatException e) {
System.out.println("java.lang.NumberFormatException: Please enter valid integers.");
} catch (ArithmeticException e) {
System.out.println("java.lang.ArithmeticException: An arithmetic error occurred.");
} catch (IllegalArgumentException e) {
System.out.println("java.lang.IllegalArgumentException: " + e.getMessage());
} catch (Exception e) {
System.out.println("An unexpected error occurred: " + e.getMessage());
}
}
}
OUTPUT:
javac MathOperation.java
java MathOperation 10 20 30 40 50