-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment8.java
More file actions
64 lines (61 loc) · 2.1 KB
/
assignment8.java
File metadata and controls
64 lines (61 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.InputMismatchException;
import java.util.Scanner;
// public class assignment8 {
// public static void main(String[] args) {
// Scanner sc = new Scanner(System.in);
// int arr[] = new int[5];
// try {
// for (int i = 0; i < 6; i++) {
// System.out.println("Enter a number:");
// arr[i] = sc.nextInt();
// }
// } catch (IndexOutOfBoundsException e) {
// System.out.println("Array Index Out of Bounds");
// } catch (InputMismatchException ex) {
// System.out.println("Input Mismatch");
// } catch (Exception e) {
// System.out.println("Exception Handled!");
// } finally {
// System.out.println("Try catch executed successfully.");
// sc.close();
// }
// }
// }
public class assignment8 {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter two integer numbers");
// Read two integers
int num1 = sc.nextInt();
int num2 = sc.nextInt();
try {
System.out.println(num1 + "/" + num2 + "="
+ (num1 / num2));
} catch (ArithmeticException e)
// multiple catch statement
{
System.out.println("Divide by 0");
} catch (Exception e)
// superclass
{
System.out.println("divide by 0");
} finally {
System.out.println("The 'try catch' is finalised.");
}
int arr[] = new int[5];
try {
for (int i = 0; i < 6; i++) {
System.out.println("Enter a number:");
arr[i] = sc.nextInt();
}
} catch (IndexOutOfBoundsException e) {
System.out.println("Array Index Out of Bounds");
} catch (InputMismatchException ex) {
System.out.println("Input Mismatch");
} catch (Exception e) {
System.out.println("Exception Handled!");
} finally {
System.out.println("Finally block!");
}
}
}