码迷,mamicode.com
首页 > 编程语言 > 详细

第七天学习内容 数组

时间:2015-03-07 09:01:00      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:

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();*/

第七天学习内容 数组

标签:

原文地址:http://www.cnblogs.com/William-1234/p/4319697.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!