What will the answer or error if I tried to perform operation divide by zero in java ?
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.
it will give answer ” infinity”.
But while I tried same program with i=0 int type.
it return me an answer with error.
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”.