-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain.java
More file actions
30 lines (25 loc) · 949 Bytes
/
Main.java
File metadata and controls
30 lines (25 loc) · 949 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
30
package ExceptionHandling;
import java.util.InputMismatchException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
try {
System.out.println("Enter a whole number to divide");
int x = scanner.nextInt();
System.out.println("Enter a whole number to divided by: ");
int y = scanner.nextInt();
int z = x / y;
System.out.println("result: " + z);
} catch (ArithmeticException e) {
System.out.println("You can't divide by 0!");
} catch (InputMismatchException e) {
System.out.println("Please enter a number!!");
} catch (Exception e) {
System.out.println("Just enters integer numbers only!");
} finally {
scanner.close();
System.out.println("This will always print");
}
}
}