C#小练习ⅱ

用户从键盘输入月份,使用switch语句输出该月份的天数

如果输入月份为2月份,则程序提示让用户输入年份,再输出结果

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace switch_compute_month_days
{
    class month
    {
        static void Main(string[] args)
        {
            Console.WriteLine("输入月份:");
            inta = int.Parse(Console.ReadLine());
            switch(a)
            {
                case1:
                case3:
                case5:
                case7:
                case8:
                case10:
                case12:
                    Console.WriteLine("此月份共有31天!");
                    break;
                case4:
                case6:
                case9:
                case11:
                    Console.WriteLine("此月份共有30天!");
                    break;
                case2:
                    Console.WriteLine("本月判断需要判断年份!请输入年份:");
                    intyear = int.Parse(Console.ReadLine());
                    if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
                    {
                        Console.WriteLine("本月份共有29天!");
                    }
                    else
                    {
                        Console.WriteLine("本月份共有28天!");
                    }
 
                    break;
 
 
                default:
                    break;
            }
 
        }
    }
}
 


 

 

输出九九乘法表:


 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace _99
{
    class Program
    {
        static void Main(string[] args)
        {
            for(int i = 1; i < 10; i++)
            {
                for(int j = 1; j < 10; j++)
                {
                    Console.Write("{0}*{1}={2,-5}", i, j, i * j);
                }
                Console.WriteLine();
            }
 
            for(int m = 1; m < 10; m++)
            {
                for(int n = 1; n <=m; n++)
                {
                    Console.Write("{0}*{1}={2,-5}", m, n, m * n);
                }
                Console.WriteLine();
            }
 
            for(int m = 1; m < 10; m++)
            {
                for(int n = m; n < 10; n++)
                {
                    Console.Write("{0}*{1}={2,-5}", m, n, m * n);
                }
               Console.WriteLine();
                for(int n = 1; n <=m; n++)
                {
                    Console.Write("{0,9}",null);
                }
              
            }
 
        }
    }
}
 


 

 

计算有固定收入的党员每月所交纳的党费。月工资收入400元及以下者,交纳月工资总额的0.5%;月工资收入401~600元者,交纳月工资总额的1%;月工资收入601~800元者,交纳月工资总额的1.5%;月工资收入801~1500元者,交纳月工资总额的2%;月工资收入1500元以上者,交纳月工资总额的3%;


 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace income
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入您的收入:");
            intincome = int.Parse(Console.ReadLine());
            while(income<0)
            {
                Console.WriteLine("输入数据不合法:请重新输入");
                income = int.Parse(Console.ReadLine());
               
            }
            if(income <= 400 && income > 0)
            {
                Console.WriteLine("应缴纳费用为:{0}", income * 0.005);
            }
            elseif (income > 400 && income <=600)
            {
                Console.WriteLine("应缴纳费用为:{0}", income * 0.01);
            }
            elseif (income > 600 && income <=800)
            {
                Console.WriteLine("应缴纳费用为:{0}", income * 0.015);
            }
            elseif (income > 800 && income <=1500)
            {
                Console.WriteLine("应缴纳费用为:{0}", income * 0.02);
            }
            else
            {
                Console.WriteLine("应缴纳费用为:{0}", income * 0.03);
            }
          
        }
    }
}
 


 

posted @ 2016-09-21 10:21  Joe.Smith  阅读(167)  评论(0)    收藏  举报