package final_lab2_task_3; import java.util.Scanner; public class MultiOperationExample { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); try { // Step 1: Read integers for array initialization System.out.print("Enter the number of elements in the array: "); int size = scanner.nextInt(); int[] array = new int[size]; System.out.println("Enter the elements of the array:"); for (int i = 0; i < size; i++) { array[i] = scanner.nextInt(); } // Step 2: Division operation System.out.print("Enter a number to divide: "); int num1 = scanner.nextInt(); System.out.print("Enter a number to divide by: "); int num2 = scanner.nextInt(); double result = num1 / num2; System.out.println("Division result: " + result); // Step 3: Access array element by index System.out.print("Enter an index to access in the array: "); int index = scanner.nextInt(); int value = array[index]; System.out.println("Element at index " + index + " is " + value); // Step 4: Parse a string to an integer System.out.print("Enter a string to parse as an integer: "); scanner.nextLine(); // Consume newline left by nextInt() String str = scanner.nextLine(); int parsedValue = Integer.parseInt(str); System.out.println("Parsed integer: " + parsedValue); } catch (ArithmeticException e) { System.out.println("Error: Division by zero is not allowed."); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Error: Array index is out of bounds."); } catch (NumberFormatException e) { System.out.println("Error: Invalid input; unable to parse string to an integer."); } finally { scanner.close(); } } }