java 高手来帮帮我啊

来源:百度知道 编辑:UC知道 时间:2024/07/12 10:23:44
import java.util.Scanner;
public class text {
public static void main(String[] args ) {
Scanner scanner = new Scanner(System.in);
System.out.print("学生人数");

int length = scanner.nextInt();
float [] score = new float[length];

for (int i = 0; i<score.length; i++ ) {
System.out.print("输入分数");

float input = scanner.nextFloat();
score[i] = input;
}
System.out.print("\n分数");
float total = 0;
for(int i = 0; i <score.length; i++) {
total = total + score[i];
System.out.print(score[i]+" ");

}

System.out.printf("\n平均:%.2f",total / score.length);

}

}
最后一句的printf 怎么改都不对啊 帮忙改一下
还有这一句
float input = scanner.nextFloat();
score[i] = input;
和这一句 ( "\n平均:%.2f",total / score.length)
不懂 也给讲讲

float input = scanner.nextFloat();
循环赋值

score[i] = input;
把input变量赋给score[i]

( "\n平均:%.2f",total / score.length)
%.2f取两位小数的意思吧 就是输出一个数该数是由该表达式的值total / score.length