「java判断闰月」java语句判断闰年
本篇文章给大家谈谈java判断闰月,以及java语句判断闰年对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、今天老师出的个狠无聊的一个JAVA编程问题.希望各位能帮忙解决下!
- 2、编程序:计算某年某月有多少天(区分闰年和闰月)?怎么编?
- 3、java中,判断一年中是否闰月,用代码怎么写出来???
- 4、编写java程序判断闰年。
- 5、java编程 输入整数判断是否闰月年,对输入double数判断是否正数
今天老师出的个狠无聊的一个JAVA编程问题.希望各位能帮忙解决下!
呵呵,确实无聊,不过学习还是必须的。代码如下:
public class TestDays {
public static void main(String[] args) {
int y, m; //定义变量,分别用来接收年月
int total = 0; //储存输入月份后有多少天
Scanner sc = new Scanner(System.in);
System.out.print("请输入年份:");
y = sc.nextInt();
System.out.print("请输入月份:");
m = sc.nextInt();
if(y =1900 y=9999)
{
if(m =1 m=12)
{
switch (m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
total = 31;
break;
case 4:
case 6:
case 9:
case 11:
total = 30;
break;
case 2:
if ((y % 100 != 0) (y % 4 == 0) || (y % 400 == 0))
{
total = 29;
}
else
{
total = 28;
}
break;
}
System.out.print(y + "年" + m + "月有" + total + "天");
}
else
{
System.out.print("月份输入有误!");
}
}
else
{
System.out.print("年份输入有误!");
}
}
}
编程序:计算某年某月有多少天(区分闰年和闰月)?怎么编?
源程序代码如下:
#include iostream
using namespace std;
int main()
{
int year, month;//定义年份月份
double a, b, c;//用于判断的变量
cout "请输入年份 月份:";//文字提示输入年份月份
cin year month;//输入年份月份
a = year % 4;//能否被4整除
c = year % 100;//能否被100整除
b = year % 400;//能否被400整除
if (((a == 0) (c != 0)) || (b == 0))//判断
{
switch (month)//大月1357811
case 1:
case 3:
case 5:
case 7:
case 9:
case 11:
{
cout "本月有31天" endl;
break;
}
switch (month)//小月4681012
case 4:
case 6:
case 8:
case 10:
case 12:
{
cout "本月有30天" endl;
break;
}
switch (month)//判断闰年否
case 2:
{
cout "本月有29天" endl;
break;
}
}
else
{
switch (month)//大月1357811
case 1:
case 3:
case 5:
case 7:
case 9:
case 11:
{
cout "本月有31天" endl;
break;
}
switch (month)//小月4681012
case 4:
case 6:
case 8:
case 10:
case 12:
{
cout "本月有30天" endl;
break;
}
switch (month)//判断闰年否
case 2:
{
cout "本月有28天" endl;
break;
}
}
return 0;
}
程序运行结果如下:
扩展资料:
其他实现方法:
#include stdio.h
#include stdlib.h
void main()
{
int year, month, days;
printf(输入年份:);
scanf(%d,year);
printf(输入月份:);
scanf(%d, month);
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days=31;
break;
case 4:
case 6:
case 9:
case 11:
days=30;
break; case 2:
if(year%4==0 year%100!=0 || year%400==0// 判断闰年
days=29;
else days=28;
break;
default:
printf(月份输入错误!\n);
exit(1);
break; }
printf(天数:%d\n, days);
}
java中,判断一年中是否闰月,用代码怎么写出来???
System.out.print("\n请选择年份: ");int year = input.nextInt();int days = 0; // 存储当月的天数boolean isRn;/* 判断是否是闰年 */if (year % 4 == 0 !(year % 100 == 0) || year % 400 == 0) { // 判断是否为闰年 isRn = true; // 闰年} else { isRn = false;// 平年}
编写java程序判断闰年。
代码如下:
public class RUN {
public static void main(String[] args) {
//布尔型判断
int year = 2000;
boolean b1 = year%4==0;
boolean b2 = year%100!=0;
boolean b3 = year%400==0;
if(b1b2||b3){
System.out.println("闰年");
}else{
System.out.println("不是闰年");
}
//用if语句判断
int year2=2018;
if(year2 % 4 == 0 year2 % 100 != 0 || year2 % 400 == 0){
System.out.println("是闰年");
}else{
System.out.println("不是闰年");
}
}
}
代码截图:
扩展资料:
闰年是公历中的名词。闰年分为普通闰年和世纪闰年。
普通闰年:能被4整除但不能被100整除的年份为普通闰年。(如2004年就是闰年,1999年不是闰年);
世纪闰年:能被400整除的为世纪闰年。(如2000年是闰年,1900年不是闰年);
闰年(Leap Year)是为了弥补因人为历法规定造成的年度天数与地球实际公转周期的时间差而设立的。补上时间差的年份为闰年。闰年共有366天(1-12月分别为31天,29天,31天,30天,31天,30天,31天,31天,30天,31天,30天,31天)。
凡阳历中有闰日(二月为二十九日)的年;闰余(岁余置闰。阴历每年与回归年相比所差的时日);
注意闰年(公历中名词)和闰月(农历中名词)并没有直接的关联,公历中只分闰年和平年,平年有365天,而闰年有366天(2月中多一天);
平年中也可能有闰月(如2017年是平年,农历有闰月,闰6月)。
参考资料:百度百科-闰年
java编程 输入整数判断是否闰月年,对输入double数判断是否正数
import java.util.* ;//导入java .util包
public class Year {
public static void main(String[] args) {
double year=0.0;
System.out.println("请用户输入要判断的年份:");
year = new Scanner(System.in).nextDouble();//键盘输入年份
if(year==(int)year)//判断用户所输入的年份是否为整数,由于年份肯定为整数的
{
//判断输入的年份是否为闰年
if((year%400==0)||(year%100!=0year%4==0))//闰年成立的判断条件
{
System.out.println("您要判断的年份是闰年!");
}
else
{
System.out.println("您要判断的年份不是闰年!");
}
}
else//如果输入的年份不是整数的话,则打印“无法判断”告知用户
{
System.out.println("您所输入的年份为非整数年份,无法判断,请输入整数年份!");
}
}
}
关于java判断闰月和java语句判断闰年的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。