-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDemo2.java
More file actions
43 lines (38 loc) · 973 Bytes
/
Copy pathDemo2.java
File metadata and controls
43 lines (38 loc) · 973 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
34
35
36
37
38
39
40
41
42
43
import java.util.InputMismatchException;
import java.util.Scanner;
public class Demo2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int firstNo = 0;
int secondNo =0;
int result = 0;
try{
System.out.println("Enter the First No ");
firstNo = scanner.nextInt();
}
catch(InputMismatchException e){
System.out.println("Only 0-9 Allowed ");
scanner.nextLine();
System.out.println("Enter the First No ");
firstNo = scanner.nextInt();
}
try{
System.out.println("Enter the Second No ");
secondNo = scanner.nextInt();
}
catch(InputMismatchException e){
System.out.println("Only 0-9 Allowed ");
scanner.nextLine();
System.out.println("Enter the Second No ");
secondNo = scanner.nextInt();
}
try{
result = firstNo/secondNo;
}
catch(ArithmeticException e){
System.out.println("U Divide a No With Zero");
}
System.out.println("Result is "+result);
scanner.close();
}
}