33570人加入学习
(89人评价)
C#编程-第一季-编程基础-宇宙最简单2021最新版

制作完成于2021年10月10日,使用Visual Studio 2019

价格 免费
using System;

namespace ConsoleApp3
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("年份闰年判断程序!\n");
            do
            {
                Console.Write("请输入年份:");
                string yearStr = Console.ReadLine();//从控制台获取年份
                yearStr = yearStr.Trim().ToLower();//去除前后空格并转化为小写字母

                if (yearStr =="q" )
                {
                    Console.WriteLine("退出程序!\n");
                    break;
                }

                //int year = int.Parse(yearStr); //字符串转整型,转换失败报出异常
                //int year = Convert.ToInt32(year);//字符串转整型,转换失败报出异常
                if (int.TryParse(yearStr,out int year))//尝试字符串转整型,转换成功返回true,转换失败返回false
                {

                    if (year < 1 || year > 9999)
                    {
                        Console.WriteLine($"年份 {year} 不在合理的范围内(1-9999),请重新输入。\n");
                        continue;
                    }

                    bool isLeapYear = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
                    Console.WriteLine($"{year}年,{(isLeapYear?"是":"不是")}闰年!\n");
                }
                else
                {
                    Console.WriteLine("输入无效,请输入一个有效的年份数字或输入'q'退出。\n");
                }

            }while (true);
        }
    }
}

 

[展开全文]

英语字母的字符可以直接比较大小。

[展开全文]

 int a = Convert.ToInt32(Console.ReadLine());
 int b = Convert.ToInt32(Console.ReadLine());
 int c = Convert.ToInt32(Console.ReadLine());
 if (a > b && a > c)
 {
     Console.WriteLine(a * a);
 }
 else if (b > a && b > c)
 {
     Console.WriteLine(b * b);
 }
 else { Console.WriteLine(c * c); 
 }

[展开全文]

convert.toint32();把输入的字符转成整数类型 

convert.tochar();把输入的字符转成字符类型

[展开全文]
using System;

namespace _014_编程题
{
    class Program
    {
        static void Main(string[] args)
        {
            //int year = Convert.ToInt32(Console.ReadLine());

            //if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
            //{
            //    Console.WriteLine("是闰年");
            //}
            //else
            //{
            //    Console.WriteLine("不是闰年");
            //}


            //int number = Convert.ToInt32(Console.ReadLine());

            //if (number < 0)
            //{
            //    Console.WriteLine(0 - number);
            //}
            //else
            //{
            //    Console.WriteLine(number);
            //}


            //int a = Convert.ToInt32(Console.ReadLine());
            //int b = Convert.ToInt32(Console.ReadLine());
            //int c = Convert.ToInt32(Console.ReadLine());
            //int max = a;
            //if (b > max)
            //{
            //    max = b;
            //}
            //if (c > max)
            //{
            //    max = c;
            //}
            //Console.WriteLine(max * max);


            char a = Convert.ToChar(Console.ReadLine());
            char b = Convert.ToChar(Console.ReadLine());
            if (a > b)
            {
                Console.WriteLine("{0}>{1}", a, b);
            }
            else
            {
                Console.WriteLine("{0}<{1}", a, b);
            }
        }
    }
}

 

[展开全文]

Convert.ToChar

字符可以直接做大小比较

[展开全文]

授课教师

问问题加入A计划,有专门负责答疑的老师哦!!!

课程特色

下载资料(1)
视频(117)
图文(3)