forked from guptaaayushi09/Hactoberfest_2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode1.cpp
More file actions
41 lines (39 loc) · 968 Bytes
/
Copy pathcode1.cpp
File metadata and controls
41 lines (39 loc) · 968 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
package com.company;
import java.util.Scanner;
class UserVerySmallNumException extends Exception{
public double a;
UserVerySmallNumException(double p)
{
a=p;
}
public String toString()
{
return "My Exception"+a+"is very less than 0.00001 ";
}
};
public class Main {
public static void divide( double a,double b) throws Exception
{
if(b<0.0001){
throw new UserVerySmallNumException(a);
}
else {
System.out.println("Divide of two number is:"+a/b);
}
}
public static void main(String[] args) throws Exception {
double a,b;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the first value:");
a=sc.nextDouble();
System.out.println("Enter the second value:");
b= sc.nextDouble();
try{
divide(a,b);
}
catch (UserVerySmallNumException e)
{
System.out.println(e);
}
}
}