打闹钟时间编程 DateTime dt = new DateTime(); dt = DateTime.Now; string t = "2015-3-6 10:00"; DateTime x = Convert.ToDateTime(t); while (true) { if (dt>=x) { Console.WriteLine("您该看新闻联播了!"); Console.WriteLine("是否关闭闹钟 Y/N"); Console.ReadLine(); if (t=="N") { x = x.AddMinutes(5); } else { break; }
} else { dt = dt.AddMinutes(1); Console.WriteLine("现在时间" + dt);
} } Console.ReadLine();
用int做闹钟 int x = 0; int y = Convert.ToInt32(Console.ReadLine()); while (true) { if (x>=y) { Console.WriteLine("您该看新闻联播了!"); Console.WriteLine("是否关闭闹钟 Y/N"); string x1=Console.ReadLine(); if (x1=="Y") { break; } else { Console.WriteLine("当前的停止条件="+y+"修改后的="+(y+5)); y += 5; } } else {
Console.WriteLine("xianzai" + x); x++; } } Console.ReadLine();
一、数组 (一)一维数组 while (true) { string[] weekdays = new string[] { "周一", "周二", "周三", "周四", "周五", "周六", "周日" }; int day = Convert.ToInt32(Console.ReadLine()); if (day<=weekdays.Length) { Console.WriteLine(weekdays[day-1]); } else { Console.WriteLine("超出长度"); } } Console.ReadLine();
while (true) { int[] weekdays = new int[8]; for (int i = 0; i < 8; i++) { weekdays[i] = i; Console.WriteLine((weekdays[i])); } Console.ReadLine(); } (二)二维数组 定义二维数组int[,]x=new int{几个一维数组,数组中的个数} 赋值循环 打工字!! string[,] a = new string[5,5] ; for (int i = 0; i <5; i++) { for (int i1 = 0; i1 <5; i1++) { Console.WriteLine("请为下标["+i+","+i1+"]的数值"+a[i,i1]); if (i==0||i1==2||i==4) { a[i, i1] = "◎"; } else { a[i, i1] = " "; } } } for (int i = 0; i <5; i++) { for (int i1 = 0; i1 <5; i1++) { Console.Write(a[i,i1]); } Console.Write(" "); } Console.ReadLine();
(三)多维数组 in[,,] x=new int 输入10个人的分数,去掉两个最高两个最低分,求平均分、 Console.WriteLine("输入人数 "); int r = Convert.ToInt32(Console.ReadLine()); int[] c = new int[r]; if (r>=5)// { for (int h = 0; h < r; h++)// { Console.WriteLine("输入第"+h+"个人成绩"); c[h] = Convert.ToInt32(Console.ReadLine()); } for (int i = 0; i <r; i++) { for (int j = 0; j <r-1; j++) { if (c[i]<c[j+1])//冒泡排序,由大到小 { int z = 0; z = c[i]; c[j] = c[i]; c[j + 1] = z; } } } int he = 0; for (int i = 0; i <r-1; i++) { he = he + c[i]; } double pj=(he-c[0]-c[1]-c[r-2]-c[r-1])/(r-4); Console.WriteLine("去掉两个最高分{0}、{1},去掉两个最低分{2},{3},最后平均分:{4}",c[0],c[1],c[r-1],c[r-2],pj); } else { Console.WriteLine("输入的人数>=5!!"); } Console.ReadLine();