forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustom_Ex3.java
More file actions
48 lines (40 loc) · 1002 Bytes
/
Custom_Ex3.java
File metadata and controls
48 lines (40 loc) · 1002 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
44
45
46
47
48
package exception;
import java.util.Scanner;
public class Custom_Ex3 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
System.out.println("Enter two numbers for subtraction : ");
int a = s.nextInt();
int b = s.nextInt();
s.close();
System.out.println("A = " + a + "\nB = " + b);
sub(a, b);
}
static void sub(int a, int b) {
int c;
if (a < b) {
try {
System.out.println("Subtraction isnot possible");
throw new NegativeAnswerException("Negative Answer Found");
} catch (NegativeAnswerException e) {
// TODO: handle exception
System.out.println(e);
}
} else {
c = a - b;
System.out.println("Subtraction is possible");
System.out.println("Answer is : " + c);
}
}
}
@SuppressWarnings("serial")
class NegativeAnswerException extends Exception {
public NegativeAnswerException(String s) {
// TODO Auto-generated constructor stub
super(s);
}
}