-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDivideByZero.java
More file actions
31 lines (24 loc) · 903 Bytes
/
DivideByZero.java
File metadata and controls
31 lines (24 loc) · 903 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
// EIGTHTEEN PROGRAM OF JAVA PRACTICAL
import java.util.Scanner;;
public class DivideByZero {
public static void main(String [] args) throws ArithmeticException{
Scanner sc=new Scanner(System.in);
System.out.println("This program is to calculate the division of two numbers hence enter two values for its division ");
try{
System.out.print("Enter the first number:");
int a=sc.nextInt();
System.out.print("Enter the second number:");
int b=sc.nextInt();
if(b==0){
throw new Exception("Divide by zero is not possible!");
}
System.out.println("The division of two number("+a+"/"+b+") is:"+(double)a/b);
}
catch(Exception e){
System.out.println(e);
}
finally{
sc.close();
}
}
}