-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample3.java
More file actions
29 lines (22 loc) · 875 Bytes
/
Copy pathExample3.java
File metadata and controls
29 lines (22 loc) · 875 Bytes
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
import java.util.Scanner;
public class Example3{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the numerator: ");
int numerator = sc.nextInt();
System.out.print("Enter the denominator: ");
int denominator = sc.nextInt();
try {
// Perform division
int result = numerator / denominator;
System.out.println("Result of division: " + result);
} catch (ArithmeticException e) {
// Handle division by zero
System.out.println("Error: Division by zero is not allowed.");
} finally {
// This block will always execute
System.out.println("Finally block executed");
}
//System.out.println("Program continues after try-catch-finally.");
}
}