double(78.5) h和float(68.3) 小數(shù)點都是一位,為什么相加就是146.8000030517578
public?class?HelloWorld{ ????public?static?void?main(String[]?args)?{ ????????double?avg1=78.5; ????????float?age3=68.3f; ????????char?sex='男'; ????????boolean?close=true; ????????int?rise=5; ????????int?avg2=(int)avg1+rise; ????????double?age4=avg1+age3; ????????System.out.println("考試平均分:"+avg1); ????????System.out.println("調整后的平均分:"+avg2); ????????System.out.println("性別:"+sex); ????????System.out.println(age3); ????????System.out.println(age4); ????????System.out.println("確認關閉嗎:"+close); ????} }
運行結果
考試平均分:78.5
調整后的平均分:83
性別:男
68.3
146.8000030517578
確認關閉嗎:true
2022-04-01
public class HelloWorld{
? ?public static void main(String[] args) {
? ? ? ? float avg1=78.5f;
? ? ? ? float age3=68.3f;
? ? ? ? char sex='男';
? ? ? ? boolean close=true;
? ? ? ? int rise=5;
? ? ? ? int avg2=(int)avg1+rise;
? ? ? ? float age4=avg1+age3;
? ? ? ? System.out.println("考試平均分:"+avg1);
? ? ? ? System.out.println("調整后的平均分:"+avg2);
? ? ? ? System.out.println("性別:"+sex);
? ? ? ? System.out.println(age3);
? ? ? ? System.out.println(age4);
? ? ? ? System.out.println("確認關閉嗎:"+close);
? ? }
}
2021-06-23