第七天学习内容 数组

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace day07
{
    class Program
    {
        static void Main(string[] args)

//  闹钟提醒
            /*        DateTime dt = new DateTime();
                     dt = DateTime.Now;
                     string t="2015/03/04 18:30";   //定义闹钟响起时间
                     DateTime a=Convert.ToDateTime(t);//并转换成datetime格式
                     while (true)
                     {

                         if (dt >= a)   //当现在时间大于等于设置时间时进入判断
                         {
                             Console.WriteLine("看新闻联播了");
                             Console.WriteLine("是否关闭闹钟 y/n");
                             string x = Console.ReadLine();  //定义一个变量接受输入的值
                             if (x == "n")
                             {

                                 a = a.AddMinutes(5);  //当输入n时时间+5,过五分钟再提醒
                             }
                             else
                             {
                                 break;   //当输入y时跳出循环
                             }
                         }
                         else   //当前时间小于设置时间时输出时间并+1
                         {
                             Console.WriteLine("现在的时间是" + dt);
                             dt = dt.AddMinutes(1);   
                         }
               
                     } 

 

         //一维数组
                     while (true)
                     {
                         string[] weekdays = new string[] {"周一","周二","周三","周四","周五","周六","周日" };
                         int day = Convert.ToInt32(Console.ReadLine());
                         if (day<=weekdays.Length)
                         {
                             Console.WriteLine(weekdays[day - 1]);
                         }
                         else
                         {
                             Console.WriteLine("输入有误");
                         }
                     }    

 

                     //二维数组 打印”田“字
                     string[,] arr = new string[5, 5] ;
                     for (int i = 0; i < 5; i++)      //控制行
                     {
                         for (int j = 0; j < 5; j++)  //控制列
                         {
                             if (i==0||i==4||j==2||j==0||j==4||i==2) //在指定位置打印●
                             {
                                 arr[i, j] = "●";
                             }
                             else
                             {
                                 arr[i, j] = "  ";
                             }
                         }
               
                     }

                     for (int i = 0; i <5; i++)   //打印数组
                     {
                         for (int j = 0; j <5; j++)
                         {
                            Console.Write(arr[i,j]);
               
                         }
                         Console.Write("\n");
                     }
           
                     Console.ReadKey(); 


            //输入十位同学的成绩,去掉两个最高分和两个最低分,再求平均分
            int[] cj = new int[10];
            for (int i = 1; i <= 10; i++)
            {
                Console.WriteLine("请输入第" + i + "位同学的分数:");
                cj[i - 1] = Convert.ToInt32(Console.ReadLine());     //输入成绩并赋值给数组
            } 
                for (int k = 0; k <10; k++)     //冒泡排序按从大到小排序
                {
                    for (int j = k+1; j < 10; j++)
                    {
                       
                        if (cj[k] <= cj[j])
                        { 
                            int a;
                            a = cj[k];
                            cj[k] = cj[j];
                            cj[j] = a;
                          
                        }
                       
                    }
                }
                for (int i = 0; i < 10; i++)
                {
                    Console.WriteLine(cj[i]);   //打印排序后的数组
                }
            double avr,sum=0;
            for (int i = 2; i <8; i++)
            {
                sum += cj[i];    //求去掉两个最高分和两个最低分之后的成绩的和
               
            }
                    avr = sum /6;  //求平均分
                    Console.WriteLine(avr);
            Console.ReadKey();*/

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。