输入全班学生的成绩,输出80分以上的学生成绩的平均成绩。(continue的用法)

用java编程写程序,输入全班学生的成绩,输出80分以上的学生成绩的平均成绩。(continue的用法)


import java.util.Scanner;  
  
public class Main {  
    public static void main(String[] args) {  
        Scanner scanner = new Scanner(System.in);  
        System.out.print("请输入全班学生的成绩:");  
        int[] scores = new int[20];  
        for (int i = 0; i < scores.length; i++) {  
            scores[i] = scanner.nextInt();  
        }  
        int sum = 0;  
        for (int i = 0; i < scores.length; i++) {  
            if (scores[i] >= 80) {  
                sum += scores[i];  
            }  
        }  
        double average = (double) sum / scores.length;  
        System.out.println("平均成绩为:" + average);  
        if (sum > 0) {  
            System.out.println("输入成绩不足80分的学生有:" + sum);  
        }  
    }  
}

全班多少人啊?


public class Test
{
public static void main(String[] args)
 {
        Scanner sc = new Scanner(System.in);
        int count = 0, num = 0;
        double sum = 0;
        System.out.print("请输入班级学生人数:");
        num = sc.nextInt();
        for(int i=0;i<num;i++)
        {
            int score = scanner.nextInt();
            if (score < 80) 
                continue;
            count++;
            sum += score;
        }
        if (count == 0) 
            System.out.println("没有80分以上的学生成绩!");
        else 
            System.out.println("80分以上学生成绩的平均成绩为:" + sum/count);
    }
 }

public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = 0, sum = 0;
        double average;
        while (true) {
            System.out.print("请输入一个学生的成绩(输入-1结束):");
            int score = scanner.nextInt();
            if (score == -1) {
                break;
            }
            if (score < 80) {
                continue;
            }
            count++;
            sum += score;
        }
        if (count == 0) {
            System.out.println("没有80分以上的学生成绩!");
        } else {
            average = (double) sum / count;
            System.out.println("80分以上学生成绩的平均成绩为:" + average);
        }
    }

import java.io.PrintStream;
import java.util.Scanner;

public class Main
{ 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        float a=0;
        float sum=0;
        int n=0;
        while(true)
        {
            a=sc.nextFloat();

            if(a==-1)break;

            if(a>=80)
            {
                sum+=a;
                n++;
            }
        }
        System.out.print(sum/n);
    }
}
 

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^