第一, 输入输出流都来自控制台。
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 Main(string[] args) 11 { 12 int year = int.Parse(System.Console.ReadLine()); 13 int month = int.Parse(System.Console.ReadLine()); 14 int day = int.Parse(System.Console.ReadLine()); 15 int days = fun(year, month, day); 16 Console.WriteLine("{0}年{1}月{2}日是该年的第{3}天。", year, month, day, days); 17 Console.ReadLine(); 18 } 19 20 static int fun(int year, int month, int day) 21 { 22 int[] mon = new int[12]{31,28,31,30,31,30,31,31,30,31,30,31}; 23 if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) 24 mon[1] = 29; 25 int days = 0; 26 for (int i=0; i < month - 1; i++) 27 days = mon[i] + days; 28 days = days + day; 29 return days; 30 } 31 } 32 }
第二, 输入输出都来自于窗口的textBox。
下面的的代码是双击“按钮”键之后的程序段
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 10 namespace WindowsFormsApplication1 11 { 12 public partial class Form1 : Form 13 { 14 public Form1() 15 { 16 InitializeComponent(); 17 } 18 19 private void button1_Click(object sender, EventArgs e) 20 { 21 int year = int.Parse(textBox1.Text); 22 int month = int.Parse(textBox2.Text); 23 int day = int.Parse(textBox3.Text); 24 int days = fun(year, month, day); 25 textBox4.Text = string.Format("{0}年{1}月{2}日是该年的第{3}天",year,month,day,days); 26 } 27 28 static int fun(int year, int month, int day) 29 { 30 int[] mon = new int[12] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 31 if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) 32 mon[1] = 29; 33 int days = 0; 34 for (int i = 0; i < month - 1; i++) 35 days = mon[i] + days; 36 days = days + day; 37 return days; 38 } 39 } 40 }
第三, 输入输出都来自于网页上的TextBox(表格)。
下面的的代码是双击“按钮”键之后的程序段
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.UI; 6 using System.Web.UI.WebControls; 7 8 namespace WebApplication1 9 { 10 public partial class _Default : System.Web.UI.Page 11 { 12 protected void Page_Load(object sender, EventArgs e) 13 { 14 15 } 16 17 protected void Button1_Click(object sender, EventArgs e) 18 { 19 int year = int.Parse(TextBox1.Text); 20 int month = int.Parse(TextBox2.Text); 21 int day = int.Parse(TextBox3.Text); 22 int days = fun(year, month, day); 23 TextBox4.Text = string.Format("{0}年{1}月{2}日是该年的第{3}天", year, month, day, days); 24 } 25 26 static int fun(int year, int month, int day) 27 { 28 int[] mon = new int[12] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 29 if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) 30 mon[1] = 29; 31 int days = 0; 32 for (int i = 0; i < month - 1; i++) 33 days = mon[i] + days; 34 days = days + day; 35 return days; 36 } 37 } 38 }
———————————————————————————————————————————————————————————————————————————
声明:
本文为 大Yi巴狼 对自己所学的知识整理和实现。
本文档欢迎自由转载,但请务必保持本文档完整或注明来之本文档。本文档未经 大Yi巴狼 同意,不得用于商业用途。最后,如果您能从这个简单文档里获得些许帮助,大Yi巴狼 将对自己的一点努力感到非常高兴;由于作者本人水平有限,如果本文档中包含的错误给您造成了不便,在此提前说声抱歉。
祝身体健康,工作顺利。