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

来源:互联网 发布:万能搬家软件好用吗 编辑:程序博客网 时间:2024/06/13 02:53

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


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


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


view plainprint?
  1. using System;  
  2. using System.Collections.Generic;  
  3. public class MyClass  
  4. {  
  5.     public static void Main()  
  6.     {  
  7.         Console.WriteLine("请输入长方形的长:");  
  8.         int a=int.Parse(Console.ReadLine());  
  9.         Console.WriteLine("请输入长方形的宽:");  
  10.         int b=int.Parse(Console.ReadLine());  
  11.         Console.WriteLine("长方形的面积为:{0}",a*b);  
  12.         Console.WriteLine("长方形的周长为:{0}",(a+b)*2);  
  13.         Console.ReadLine();       
  14.     }  
  15. }  

view plainprint?
  1. using System;  
  2. using System.Collections.Generic;  
  3. public class MyClass  
  4. {  
  5.     public static void Main()  
  6.     {  
  7.         Console.WriteLine("请输入日期:");  
  8.         int year=int.Parse(Console.ReadLine());  
  9.         if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))  
  10.   
  11.   
  12.         {  
  13.             Console.WriteLine("为闰年");  
  14.         }  
  15.         else  
  16.         {  
  17.             Console.WriteLine("不为闰年");  
  18.         }  
  19.         Console.ReadLine();       
  20.     }  
  21.       
  22. }  


view plainprint?
  1. using System;  
  2. using System.Collections.Generic;  
  3.   
  4. public class MyClass  
  5. {  
  6.     public static void Main()  
  7.     {  
  8.         Console.WriteLine("请输入第1个数字:");  
  9.         int a = int.Parse(Console.ReadLine());  
  10.         Console.WriteLine("请输入第2个数字:");  
  11.         int b = int.Parse(Console.ReadLine());  
  12.         Console.WriteLine("请输入第3个数字:");  
  13.         int c = int.Parse(Console.ReadLine());  
  14.         int temp = 0;  
  15.         if(a > b)  
  16.         {  
  17.             temp = a;  
  18.             a = b ;  
  19.             b = temp;  
  20.         }  
  21.         if(a > c)  
  22.         {  
  23.             temp = a;  
  24.             a = c;  
  25.             c = temp;      
  26.         }  
  27.         if (b > c)  
  28.         {  
  29.             temp = b;  
  30.             b =  c;  
  31.             c = temp;  
  32.         }  
  33.   
  34.         Console.WriteLine("最大的数: {0}",c);  
  35.         Console.ReadLine();  
  36.           
  37.     }  
  38. }  


原创粉丝点击