-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQue-34.java
More file actions
22 lines (22 loc) · 773 Bytes
/
Copy pathQue-34.java
File metadata and controls
22 lines (22 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//Write a program that accepts 2 integers x and y and computes z=x/y. Create an exception using throws which checks if z is less then 10 and if yes it prints number is too small catch exception using throw. Also add finally block that prints the sum of x and y.
//By: Parth Panjwani
class Que34 {
public static void main(String[] args) {
int x = 10;
int y = 5;
int z = 0;
try {
z = x/y;
if (z < 10) {
throw new Exception("Number is too small");
}
System.out.println("Z: "+z);
}
catch(Exception e) {
System.out.println(e);
}
finally {
System.out.println("Sum of x and y: "+(x+y));
}
}
}