-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTryCatch.java
More file actions
34 lines (24 loc) · 761 Bytes
/
Copy pathTryCatch.java
File metadata and controls
34 lines (24 loc) · 761 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
31
32
33
package LearningPackage;
import java.util.InputMismatchException;
import java.util.Scanner;
public class TryCatch {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
do {
try {
System.out.println("Enter first num: ");
int n1 = sc.nextInt();
System.out.println("Enter second num: ");
int n2 = sc.nextInt();
int sum = n1 / n2;
System.out.println(sum);
break;
} catch (InputMismatchException e){
System.out.println("You can only enter int");
sc.next();
} catch (Exception e){
System.out.println("You cant do that");
}}while (true);
sc.close();
}
}