如何从用户那里获得输入并提供反馈

问题描述 投票:0回答:1

我是编码方面的新手-刚刚开始。构建成功,但是我想添加输入输出以得到消费者的响应,以检查它是否确实有效。谢谢

using System;

namespace LeapYear
{
    public static class Leap
    {
        static void Main(string[] args)

        {
            Console.WriteLine("Enter a year ");
            Console.ReadLine();
        }

        public static bool IsLeapYear(int year)
            { 

            if (year % 4 == 0 && year % 100 != 0 || year % 400 ==0)

            {
                return true;
            }

            return false;
        }

    }
}
c# input output console-application
1个回答
1
投票

您在这里:

using System;

public class Program
{
    public static void Main()
    {
        Console.WriteLine("Enter a year ");

        //Console.ReadLine returns the entered data as a string
        var yearString = Console.ReadLine();

        //Convert the string to an int
        int year = Int32.Parse(yearString);

        //Now we can call your function, passing the year variable and recording the bool value passed back
        var isLeapYearAnswer = IsLeapYear(year);

        //Print the answer to the console
        Console.WriteLine(isLeapYearAnswer);
    }

    public static bool IsLeapYear(int year)
    { 
        if (year % 4 == 0 && year % 100 != 0 || year % 400 ==0)
            {
                return true;
            }
        else
        {
            return false;
        }
    }
}

这里是dotnetfiddle

© www.soinside.com 2019 - 2024. All rights reserved.