java program using int and double

前端 未结 7 908
礼貌的吻别
礼貌的吻别 2020-12-21 00:16

I have written a simple Java program as shown here:

public class Test {

    public static void main(String[] args) {
        int i1 =2;
        int i2=5;
           


        
7条回答
  •  再見小時候
    2020-12-21 00:24

    Since i1=2 and i2=5 are integer type and when you divide (2/5) them, It gives integer value (0) because fractional part(.4) get discarded. So put (double)i1/i2 on the equation.

提交回复
热议问题