个人感觉这样写求平均年龄更准确点:
int sum=age1+age2+age3+age4;
double avg=sum/4.0;
int minus=age1-age2;
int newAge=--age1;
System.out.println("年龄总和:"+sum);
System.out.println("平均年龄:"+avg);
System.out.println("年龄差值:"+minus);
System.out.println("自减后的年龄:"+newAge);
int sum=age1+age2+age3+age4;
double avg=sum/4.0;
int minus=age1-age2;
int newAge=--age1;
System.out.println("年龄总和:"+sum);
System.out.println("平均年龄:"+avg);
System.out.println("年龄差值:"+minus);
System.out.println("自减后的年龄:"+newAge);
2015-02-08
public class HelloWorld {
public static void main(String[] args) {
System.out.println ("我爱慕课网!");
System.out.println ("www.imooc.com!");
}
}
public static void main(String[] args) {
System.out.println ("我爱慕课网!");
System.out.println ("www.imooc.com!");
}
}
2015-02-08
import java.util.Arrays;
public class HelloWorld {
//完成 main 方法
public static void main(String[] args) {
int scores[]={89,-23,64,91,119,52,73};
HelloWorld hello =new HelloWorld();
hello.bestThree(scores);
}
public class HelloWorld {
//完成 main 方法
public static void main(String[] args) {
int scores[]={89,-23,64,91,119,52,73};
HelloWorld hello =new HelloWorld();
hello.bestThree(scores);
}
public void bestThree(int scores[]){
for(int i=0; i<scores.length; i++){
if (scores[i]<0 || scores[i]>100){
for(int j=i;j<scores.length-1; j++){
scores[j]=scores[j+1];
}
i--;
}
}
for(int i=0; i<scores.length; i++){
if (scores[i]<0 || scores[i]>100){
for(int j=i;j<scores.length-1; j++){
scores[j]=scores[j+1];
}
i--;
}
}
Arrays.sort(scores);
System.out.println("考试成绩前三名为:"+"\n"+scores[scores.length-1]+"\n"+scores[scores.length-2]+"\n"+scores[scores.length-3]);
}
System.out.println("考试成绩前三名为:"+"\n"+scores[scores.length-1]+"\n"+scores[scores.length-2]+"\n"+scores[scores.length-3]);
}