-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexptncstmr.java
More file actions
39 lines (39 loc) · 966 Bytes
/
Copy pathexptncstmr.java
File metadata and controls
39 lines (39 loc) · 966 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
package prjjava;
import java.util.Scanner;
public class exptncstmr {
public static void main(String[] args) {
ByZero divByZeroException = new ByZero ("Division By Zero");
Scanner sc = new Scanner(System.in);
char ch='y';
int firstNumber, secondNumber;
System.out.println("Program to perform division");
while(ch=='y') {
System.out.print("Enter Number-1:");
firstNumber=sc.nextInt();
System.out.print("Enter Number-2:");
secondNumber=sc.nextInt();
try {
if (firstNumber==0 || secondNumber==0) {
throw divByZeroException;
}
else {
int result=firstNumber/secondNumber;
System.out.println("Result="+result);
}
}
catch(ByZero e) {
System.out.println(e.getMessage());
}
finally {
System.out.println("End of operation");
System.out.println("Do you want to continue?(y/n)");
ch=sc.next().charAt(0);
}
}
}
}
class ByZero extends Exception {
ByZero (String str) {
super(str);
}
}