c# - 我如何制作 ac# 程序来知道一年是世界杯还是奥运会
问题描述
所以我想制作一个程序,它知道一年是世界杯还是奥运会,其他任何一年都会“一无所有”。而且我想让这些年在 2000-2100 之间。
Console.Write("Please enter a year between 2000-2100: ");
int year;
Int32.TryParse(Console.ReadLine(), out year);
Console.WriteLine("You wrote : " + year);
If (year%4 == 0 )
{
Console.WriteLine("World cup");
}
else if (year%4 == 0)
{
Console.WriteLine("Olympic games");
}
我已经做到了这一点,但我无法让程序知道世界杯和奥运会之间的区别。
我给大家举个例子。我对编程很陌生。奥运会每 4 年举行一次,例如。2000, 2004, 2008, 2012, 2016 等等。如果年份能被 4 整除,那么它就是奥林匹克年。足球世界杯是两届奥运会之间的偶数年,例如。2002、2006、2010、2014、2018 等等。也就是说,如果这一年是偶数年而不是奥运年,那么它就是足球世界杯。每隔一年都会给出文本“今年没什么特别的”
像2003年的“今年没什么特别的” 2004年的“奥运年” 2006年的“世界杯”
using System;
namespace TEST
{
class Program
{
static void Main(string[] args)
{
Console.Write("Write a year between 1950-2050: ");
int year;
Int32.TryParse(Console.ReadLine(), out year);
Console.WriteLine("You wrote: " + year);
if (year < 1950)
{
Console.WriteLine("1950-2050 not under");
}
else if (year > 2050)
{
Console.WriteLine("1950-2050 not over");
}
Console.ReadKey();
}
这是到目前为止有效的代码。
解决方案
21 世纪的第一届 FIFA 世界杯是在 2002 年。您需要添加 2 才能获得余数。
if ((year+2)%4 == 0 )
{
Console.WriteLine("FIFA World Cup and Winter Olympics");
}
推荐阅读
- python - PermissionError: [Errno 1] 在 iPadOS 14 上使用 Pyto 时不允许操作
- angular - 在 rxjs 中过滤主题
- php - 如何在默认情况下列出 YII 命名空间?
- mule - 在 Mac 中导入 Mule 4 不显示 dataweave 元数据
- ios - 在 Cocoapods 中使用预编译时是否可以在源代码和二进制文件之间切换
- ruby-on-rails - Rails 缓存存储:如何使用密码配置 redis_cache_store
- line - 使用 OpenLayers 基于缩放级别显示功能
- flutter - 名为“scrollable_positioned_list”的颤振小部件如何判断它已滚动到顶部?
- php - 如何在不乘以php中的零的情况下获得数组的乘积
- python - 我可以在本地服务器和 Ubuntu 服务器上运行 Django 应用程序吗?