Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fd8185b

Browse files
Add files via upload
1 parent 7a7e798 commit fd8185b

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

‎Misc Programmes/DivideByZero.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import java.io.*;
2+
3+
@SuppressWarnings("serial")
4+
class myException extends Exception{
5+
public String toString()
6+
{
7+
return("DivideByZero Exception");
8+
}
9+
}
10+
/**
11+
* DivideByZero
12+
*/
13+
class DivideByZero {
14+
static float compute(float n,float b)throws myException{
15+
if (b==0)
16+
{
17+
throw new myException();
18+
}
19+
else
20+
{
21+
return (n/b);
22+
}
23+
}
24+
public static void main(String[] args) throws IOException{
25+
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
26+
System.out.println("Enter two numbers:");
27+
float a=Float.parseFloat(br.readLine());
28+
float b=Float.parseFloat(br.readLine());
29+
float q=-1;
30+
try{
31+
q=compute(a, b);
32+
}
33+
catch(myException e)
34+
{
35+
System.out.println(e);
36+
}
37+
finally{
38+
if(q==-1)
39+
{
40+
System.out.println("Error Ocurred");
41+
}
42+
else{
43+
System.out.println(q);
44+
}
45+
}
46+
47+
}
48+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /