傳智播客.Net培訓就業班入學測試題

2、對學員的結業考試成績評測,要求在控制檯中提示用戶輸入學員考試成績,寫一個方法,根據用戶輸入的成績,返回一個等級;
90分以上A級、80~90分B級、70~80分C級、60~70分B級、60分以下C級。

如圖所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("請輸入你的考試成績:");
            int score =Convert.ToInt32(Console.ReadLine());
            switch (score/10)
            {
                case 10:
                Console.WriteLine("非常棒!");
                break;
                case 9:
                Console.WriteLine("優秀");
                break;
                case 8:
                Console.WriteLine("優秀");
                break;
                case 7:
                Console.WriteLine("良好");
                break;
                case 6:
                Console.WriteLine("及格");
                break;
                default:
                Console.WriteLine("不及格!");
                break;
            }
            Console.ReadLine();
        }
    }
}

3、在控制檯中提示用戶輸入一個年齡,如果用戶輸入的年齡大於18歲,則提示用戶”可以查看”,如果小於10歲,則提示用戶“不可以查看”,如果在10歲到18歲之間,則提示用戶 “是否繼續查看?(yes/no)”,如果用戶輸入yes,則提示可以查看,否則提示不可以查看。

如圖所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("請輸入你的年齡:");
            int age =Convert.ToInt32(Console.ReadLine());
            if (age>= 18)
            {
                Console.WriteLine("可以查看!");
            }
            if (age < 18 && age >= 10)
            {
                Console.WriteLine("看請輸入Y,不看輸入N");
                string str = Console.ReadLine();
                if (str == "y" || str == "Y")
                {
                    Console.WriteLine("強行查看");
                }
                else
                {
                    Console.WriteLine("88");
                }
            }
            if (age < 10)
            {
                Console.WriteLine("年齡太小不可以查看");
            }
            Console.ReadLine();
        }
    }
}

4、在控制檯中提示用戶首先輸入一個年份,再提示用戶輸入一個月份,請根據用戶輸入的年份和月份來輸出這個月有多少天(需要判斷是否是閏年)。

如圖所示:
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("請輸入年分");
            int year = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("請輸入月分");
            int month = Convert.ToInt32(Console.ReadLine());
            if(month == 2)
            {
                if (year % 4 == 0)
                {
                    Console.WriteLine("{0}年{1}月有29天", year, month);
                }
            }
            else
            {
                int[] arr = new int[] { 1, 3, 5, 7, 8, 10, 12 };
                
                if ((Array.IndexOf(arr, month)) == -1)
                {
                    Console.WriteLine("{0}年{1}月有30天", year, month);
                }
                else
                {
                    Console.WriteLine("{0}年{1}月有31天", year, month);
                }
            }
            Console.ReadLine();
        }
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章