学习软件设计——C#练习(1)

C#练习(1~8)源代码下载请到http://download.****.net/detail/hsttmht/3751088

引用请注明http://blog.****.net/hsttmht

1.编写一个类,要求从控制台输入长方形的长和宽,计算面积和周长并且输出到控制台。


2.编写一个类,要求从控制台输入年份,计算输入的年份是否为闰年,闰年的判断是能被4整除并且不能被100整除,或者是能被400整除的年份
bool 是否为闰年 = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);


3、编写一个类,要求从控制台输入3个数字,计算输入的3个数中最大的数,并且输出。


using System; using System.Collections.Generic; public class MyClass { public static void Main() { Console.WriteLine("请输入长方形的长:"); int a=int.Parse(Console.ReadLine()); Console.WriteLine("请输入长方形的宽:"); int b=int.Parse(Console.ReadLine()); Console.WriteLine("长方形的面积为:{0}",a*b); Console.WriteLine("长方形的周长为:{0}",(a+b)*2); Console.ReadLine(); } }
using System; using System.Collections.Generic; public class MyClass { public static void Main() { Console.WriteLine("请输入日期:"); int year=int.Parse(Console.ReadLine()); if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { Console.WriteLine("为闰年"); } else { Console.WriteLine("不为闰年"); } Console.ReadLine(); } }


using System; using System.Collections.Generic; public class MyClass { public static void Main() { Console.WriteLine("请输入第1个数字:"); int a = int.Parse(Console.ReadLine()); Console.WriteLine("请输入第2个数字:"); int b = int.Parse(Console.ReadLine()); Console.WriteLine("请输入第3个数字:"); int c = int.Parse(Console.ReadLine()); int temp = 0; if(a > b) { temp = a; a = b ; b = temp; } if(a > c) { temp = a; a = c; c = temp; } if (b > c) { temp = b; b = c; c = temp; } Console.WriteLine("最大的数: {0}",c); Console.ReadLine(); } }

学习软件设计——C#练习(1)