看了半天,不知道问题在那里
int sum=age1+age2+age3+age4;
double avg=sum/4;
int minus=agel-age2;
int newAge=--age1;
int sum=age1+age2+age3+age4;
double avg=sum/4;
int minus=agel-age2;
int newAge=--age1;
2016-02-14
public class HelloWorld { public static void main(String[] args) { int age1 = 24; int age2 = 18; int age3 = 36; int age4 = 27; int sum = age1 + age2 + age3 + age4; // double avg=sum/4; 可以编译,但是逻辑是错的,得到的是int转成的double double avg = sum / 4.0; int minus = age1 - age2; // age1不是agel! int newAge = --age1; System.out.println("年龄总和:" + sum); System.out.println("平均年龄:" + avg); System.out.println("年龄差值:" + minus); System.out.println("自减后的年龄:" + newAge); } }
建议你换个字体以示区别
举报