What will the answer or error if I tried to perform operation divide by zero in java ?

What will the answer or error if I tried to perform operation divide by zero in java ?

Either

1. Infinity or

2. divide by zero error.

As the mathematical term, if you try to divide any number by zero then it will gives answer of infinite. And as the program if we are going to make any calculator it becomes necessary for us to know this.

Answer of the above question, both are true in different condition;

look at image 1, I’m trying to divide by i=0 of float type.

 

[Image 1]

it will give answer ” infinity”.

[Image 2]

But while I tried same program with i=0 int type.

[Image 3]

it return me an answer with error.

[Image 4]

what is the reason behind this?

Float : basically use to assign fraction value, if i am assign value

float i =0; means, there may chances of having something after lots of zero and dot.

Int: integer strictly define around value. if i assign int i =0. Means value of i is 0 No any possibility of any value after 0. It’s around figure.

So JAVA is return two kind of answer, If we use float then ” infinity” and while using integer than show error, of “DIVIDE BY ZERO”.

Share Post