• 函数的应用


    10个评委打分,去掉两个最高分和两个最低分,求平均分

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 
     6 namespace ConsoleApplication1
     7 {
     8     class Class1
     9     {
    10         static void Main(string[] args)
    11         {
    12             int[] a = new int[10];
    13             //亮分
    14             ShuRu(a);
    15 
    16             //排序
    17             PaiXu(a);
    18 
    19             //运算求平均
    20             double avg = YunSuan(a);
    21 
    22             //输出显示
    23             ShuChu(a, avg);
    24         }
    25 
    26         private static void ShuChu(int[] a, double avg)
    27         {
    28             Console.WriteLine("去掉两个最高分:" + a[0] + "" + a[1]);
    29             Console.WriteLine("去掉两个最低分:" + a[a.Length - 1] + "" + a[a.Length - 2]);
    30             Console.WriteLine("该选手最终得分为:" + avg);
    31         }
    32 
    33         private static double YunSuan(int[] a)
    34         {
    35             //求总分
    36             int sum = 0;
    37             for (int i = 2; i <= a.Length - 3; i++)
    38             {
    39                 sum += a[i];
    40             }
    41             //求平均
    42             double avg = (1.0 * sum) / (a.Length - 4);
    43             return avg;
    44         }
    45 
    46         private static void PaiXu(int[] a)
    47         {
    48             for (int i = 1; i <= a.Length - 1; i++)
    49             {
    50                 for (int j = 1; j <= a.Length - i; j++)
    51                 {
    52                     if (a[j] > a[j - 1])
    53                     {
    54                         int temp = a[j];
    55                         a[j] = a[j - 1];
    56                         a[j - 1] = temp;
    57                     }
    58                 }
    59             }
    60         }
    61 
    62         private static void ShuRu(int[] a)
    63         {
    64             for (int i = 0; i < a.Length; i++)
    65             {
    66                 Console.Write("请第" + (i + 1) + "号评委亮分:");
    67                 a[i] = Convert.ToInt32(Console.ReadLine());
    68             }
    69         }
    70     }
    71 }

    天气预报

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 
     6 namespace ConsoleApplication1
     7 {
     8     class Program
     9     {
    10         static void M1ain(string[] args)
    11         {
    12             ShowHeader();
    13 
    14             string city = ShuRu();
    15 
    16             string jieguo = YunSuan(city);
    17 
    18             Console.WriteLine("天气预报仅做参考:" + jieguo);
    19 
    20         }
    21 
    22         private static string YunSuan(string city)
    23         {
    24             //天气
    25             string[] s = new string[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "多云", "小雨", "中雨", "大雨", "暴雨", "雷阵雨", "小雪", "中雪", "大雪", "", "" };
    26             Random rand = new Random();
    27             int n = rand.Next(s.Length); //天气的下标.
    28             string tq = s[n];
    29 
    30             //气温
    31             int c = rand.Next(70);
    32             c -= 30;
    33 
    34             string jieguo = "明天的天气情况:" + city + ",天气:" + tq + ",气温:" + c;
    35             return jieguo;
    36         }
    37 
    38         private static string ShuRu()
    39         {
    40             Console.Write("城市:");
    41             string city = Console.ReadLine();
    42             return city;
    43         }
    44 
    45         private static void ShowHeader()
    46         {
    47             Console.WriteLine("*************天气预报****************");
    48             Console.WriteLine("********淄博气象台权威发布****************");
    49             Console.WriteLine("********如果出现异常 ,纯属偶然****************");
    50             Console.WriteLine("*****仅做个人测试与爱好使用,不要用作商业运营**********");
    51         }
    52         
    53     }
    54 }
  • 相关阅读:
    jquery选择器
    js中的闭包技术
    idea创建servlet不能创建:
    JSP页面不解析EL表达式的原因
    大对象数据LoB的应用
    缓冲流、转换流、序列化流相关流知识点
    jdk5.0新特性(注解)
    EKT相关知识(Class类对象的方法补充)
    java中调用存储过程或函数
    Java 缓冲流
  • 原文地址:https://www.cnblogs.com/viven/p/4192417.html
Copyright © 2020-2023  润新知