⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 averager.java

📁 java编程代码
💻 JAVA
字号:

import java.util.Scanner;

public class Averager
{
    public static void main(String[] args)
    {
      Scanner keyboard = new Scanner(System.in);

        System.out.println("Enter a list of nonnegative scores.");
        System.out.println("Mark the end with a negative number.");
        System.out.println("I will compute their average.");

        double next, sum = 0; 
        int count = 0;

        next = keyboard.nextDouble( );
        while(next >= 0)
        {
            sum = sum + next;
            count++;
            next = keyboard.nextDouble( );
        }

        if (count == 0)
            System.out.println("No scores entered.");
        else
        {
            double average = sum/count;
            System.out.println(count + " scores read.");
            System.out.println("The average is " + average);
        }
    }
}

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -