赞
踩
- import java.util.Scanner;
-
- public class TestWhile {
- public static void main(String[] args){
- Scanner in =new Scanner(System.in);
- float score=0,avg=0,sum=0;
- int n = 0;
-
- while(score!=-1){
- System.out.println("请输入第"+(n+1)+"个学生成绩");
- score=in.nextFloat();
-
- if(score!=-1){
- n++;
- sum=score+sum;
- }
-
- }
- avg=sum/n;
- System.out.println("总分:"+sum+"平均分:"+avg);
- }
- }
ps:需要什么java练习题的答案可以评论,关注后续博客
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。