zoukankan      html  css  js  c++  java
  • 定义一个长度为10的整数说组,可用于保存用户通过控制台输入的10个整数,并计算他们的最大最小平均值。

     1 import java.util.Scanner;
     2 public class ArithMetic {
     3     public static void main(String[] args) {
     4         calcArr();
     5     }
     6     public static void calcArr()
     7     {
     8         int[] arr = new int[10];
     9         int max = Integer.MAX_VALUE;
    10         int min = Integer.MIN_VALUE;
    11 int total = 0;
    12 int avg = 0;
    13         Scanner scan = new Scanner(System.in);
    14         for (int i = 0; i < arr.length; i++) {
    15             String s = "a";
    16             while(!s.matches("^[0-9]+$"))
    17             {
    18                 //System.out.printf("请输入第%d个数%n", i+1);
    19                 System.out.println(String.format("输入第%d个数", i+1));
    20                 s = scan.next();
    21             }
    22             arr[i] = Integer.parseInt(s);
    23             if(max < arr[i])
    24                 max = arr[i];
    25             if(min > arr[i])
    26                 min = arr[i];
    27             total += arr[i];
    28         }
    29         System.out.println("最小值:"+min);
    30         System.out.println("最大值:"+max);
    31         System.out.println("平均值:"+total/arr.length);
    32     }
    33 }
  • 相关阅读:
    Nginx 集群 反向代理多个服务器
    Nginx 反向代理
    Nginx 图片服务器
    网鼎杯 pwn 记录
    demo.testfire.net 靶场测试流程记录
    靶场测试系列(已办清单)
    Burp Suite插件推荐
    ida不错的插件记录
    0ctf2017-babyheap
    0ctf2018 pwn
  • 原文地址:https://www.cnblogs.com/masterlibin/p/4748985.html
Copyright © 2011-2022 走看看