慕无忌0479860
2021-06-22 21:12
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
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);
}
}
考试平均分:78.5 调整后的平均分:83 性别:男 68.3 146.8 确认关闭吗:true
package com.imooc; public class Demo02{ public static void main(String[] args) { double avg1=78.5; int age3= (int) 68.3; 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); } }
float的问题,在后面age4里应该是因为avg1+(float)age3才出错
Java入门第一季(IDEA工具)升级版
1165172 学习 · 17581 问题
相似问题