using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
/*
*瑞年的规定是:能被4整除,但是不能被100整除。或者能被400整除
*提示:1,3,5,7,8,10,12为31天
*4,6,9,11为30天
*2月瑞年为29天,否则28天
*/
int year, month, day;
bool shRui = false; Console.WriteLine("请输入年份:");
year = int.Parse(Console.ReadLine());
Console.WriteLine("请输入月份:");
month = int.Parse(Console.ReadLine()); if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
shRui = true;//是瑞年
if (shRui == true)
{
day = 29;
}
else
{
day = 28;
}
}
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
day = 31;
}
else if(month == 4 || month == 6 || month == 9 || month == 11)
{
day = 30;
}
Console.WriteLine(year+"年"+month+"月有"+day+"天");
}
}
}错误提示:
错误 1 使用了未赋值的局部变量“day”
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
/*
*瑞年的规定是:能被4整除,但是不能被100整除。或者能被400整除
*提示:1,3,5,7,8,10,12为31天
*4,6,9,11为30天
*2月瑞年为29天,否则28天
*/
int year, month, day;
bool shRui = false; Console.WriteLine("请输入年份:");
year = int.Parse(Console.ReadLine());
Console.WriteLine("请输入月份:");
month = int.Parse(Console.ReadLine()); if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
shRui = true;//是瑞年
if (shRui == true)
{
day = 29;
}
else
{
day = 28;
}
}
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
day = 31;
}
else if(month == 4 || month == 6 || month == 9 || month == 11)
{
day = 30;
}
Console.WriteLine(year+"年"+month+"月有"+day+"天");
}
}
}错误提示:
错误 1 使用了未赋值的局部变量“day”
shRui = true;//是瑞年
if (shRui == true)
{
day = 29;
}
else
{
day = 28;
} 下面那个if判断有什么用嘛??? 运行1w年 它也是true
(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)这个条件写错鸟
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication20
{
class Program
{
public int Datareturn(int year,int month)
{
bool shRui = false;
int day=0;
if ((year % 4 == 0 && year % 100 != 0)|| year % 400 == 0)
{
shRui = true;//是瑞年
if (shRui == true)
{
day = 29;
}
else
{
day = 28;
}
}
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
day = 31;
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
day = 30;
}
return day;
}
static void Main(string[] args)
{
Program pr = new Program(); /*
*瑞年的规定是:能被4整除,但是不能被100整除。或者能被400整除
*提示:1,3,5,7,8,10,12为31天
*4,6,9,11为30天
*2月瑞年为29天,否则28天
*/
int year, month, day;
Console.WriteLine("请输入年份:");
year = int.Parse(Console.ReadLine());
Console.WriteLine("请输入月份:");
month = int.Parse(Console.ReadLine());
day = pr.Datareturn(year,month);
Console.WriteLine(year+"年"+month+"月有"+day+"天");
}
}
}
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
shRui = true;//是瑞年
if (shRui == true)
{
day = 29;
}
else
{
day = 28;
}
} 还有2月的你有问题
要改: if ((year%4==0&& year%100!=0)|| year%400==0)
{
shRui=true;//是瑞年
day=29;
}
else
{
shRui=false;
day=28;
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication20
{
class Program
{
public int Datareturn(int year,int month)
{
bool shRui = false;
int day=0;
if ((year % 4 == 0 && year % 100 != 0)|| year % 400 == 0)
{
shRui = true;//是瑞年
if (shRui == true)
{
day = 29;
}
else
{
day = 28;
}
}
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
day = 31;
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
day = 30;
}
return day;
}
static void Main(string[] args)
{
/*
*瑞年的规定是:能被4整除,但是不能被100整除。或者能被400整除
*提示:1,3,5,7,8,10,12为31天
*4,6,9,11为30天
*2月瑞年为29天,否则28天
*/
int year, month, day;
bool shRui = false; Console.WriteLine("请输入年份:");
year = int.Parse(Console.ReadLine());
Console.WriteLine("请输入月份:");
month = int.Parse(Console.ReadLine());
day = 0;
if (month == 2)
{
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
day = 29;
}
else
{
day = 28;
}
}
else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
day = 31;
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
day = 30;
}
Console.WriteLine(year+"年"+month+"月有"+day+"天");
}
}
}
C# codeif (year%4==0&& year%100!=0|| year%400==0)
{
shRui=true;//是瑞年if (shRui==true)
{
day=29;
}else
{
day=28;
}
}
还有2月的你有问题——————————————————————————
请问 我的2月是什么问题 能具体回答下嘛
{
/*
*瑞年的规定是:能被4整除,但是不能被100整除。或者能被400整除
*提示:1,3,5,7,8,10,12为31天
*4,6,9,11为30天
*2月瑞年为29天,否则28天
*/
int year, month, day;
bool shRui = false; Console.WriteLine("请输入年份:");
year = int.Parse(Console.ReadLine());
Console.WriteLine("请输入月份:");
month = int.Parse(Console.ReadLine());
day = 0;
if (month == 2)
{
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
day = 29;
}
else
{
day = 28;
}
}
else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
day = 31;
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
day = 30;
}
Console.WriteLine(year+"年"+month+"月有"+day+"天");
}
这样已经好了没什么问题了
if (month >= 1 && month <= 12)
{
if (month == 2)
{
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
day = 29;
}
else
{
day = 28;
}
}
else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
day = 31;
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
day = 30;
}
Console.WriteLine(year + "年" + month + "月有" + day + "天"); }
else
{
Console.WriteLine("月分输入有误"); }