平均值咋回事?他提示我平均值是26.0,咋弄啊?
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;
??????? int avg=sum/4;
??????? int minus=age1-age2;
??????? int newAge=age1--;
??
??
??
???? System.out.println("年齡總和:"+sum);
??? ?System.out.println("平均年齡:"+avg);
??System.out.println("年齡差值:"+minus);
??System.out.println("自減后的年齡:"+newAge);
?}
}
2016-10-21
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=(int)sum/4;###################### 括號(hào)里面那個(gè)強(qiáng)制轉(zhuǎn)換
int minus=age1-age2;
int newAge=--age1;
? ?System.out.println("年齡總和:"+sum);
? ? System.out.println("平均年齡:"+avg);
System.out.println("年齡差值:"+minus);
System.out.println("自減后的年齡:"+newAge);
}