
public
class
Birthday
{
int
year;
int
month;
int
day;
public
Birthday(int
y,
int
m,
int
d)
{
//
括号内逗号,写成了分号
year
=
y;
month
=
m;
day
=
d;
}
public
void
isLeapYear()
{//
这行同上
//
boolean
leapyear=int
a=year/4&&(int
b=year/100&&int
c=year/400);
boolean
leapyear
=
false;
if
(thisyear
%
100
==
0
&&
thisyear
%
400
==
0)
{
leapyear
=
true;
}
else
if
(thisyear
%
4
==
0)
{
leapyear
=
true;
}
Systemoutprintln("您所输入的年份是闰年吗?"
+
leapyear);
}
public
static
void
main(String[]
args)
{
Birthday
Bri1
=
new
Birthday(2000,
10,
7);//
整型写成了字符串
Bri1isLeapYear();
}
}
程序错误挺多的,我给改了改,不知道还是不是你的原意~~
/
/
/
@author qingsongwang
/
import javautil;
public class B {
public static boolean isRun(int year)
{
return (year % 4 != 0 )|| (year % 100 == 0 )&& (year % 400 != 0);
}
public static void main(String[] args) {
Scanner input=new Scanner(Systemin);
int year;
Systemoutprintf("你输入的年份是:%s", year=inputnextInt());
if(isRun(year)){
Systemoutprint("(是闰年)");
}
else{
Systemoutprint("(不是闰年)");
}
}
}
直接运行这个程序即可!
public class LeapYear {
public static void main(String[] args) {
//colcount一行的个数统计
int colCount=0;
//yearNum闰年数统计
int yearNum=0;
for (int i = 101; i <= 2100; i++) {
//1能被4整除而不能被100整除
//2能被400整除
if((i%4==0&&i%100!=0)||i%400==0){
Systemoutprint(i+" ");
colCount++;
yearNum++;
}
if(colCount>9){
Systemoutprintln();
colCount=0;
}
}
Systemoutprintln("从101到2100 期间闰年的数目:"+yearNum);
}
}
if(a%4==0&&a%100!=0)
{
systemoutprintln("闰年。")
}
else if(a%400==0)
{
systemoutprintln("闰年。")
}
esle{
systemoutprintln("不是闰年。")
}
想写一个代码就把下面标识符改一下就行了
import javautilregexMatcher;
import javautilregexPattern;
public class 第几天 {
public static void main(String[] args) {
try {
Systemoutprintln(相差天数("2016-7-30", "2015-7-30"));
} catch (Exception e) {
eprintStackTrace();
}
}
private static Pattern p = Patterncompile("(\\d{4})-(\\d{1,2})-(\\d{1,2})");
public static int 相差天数(String a, String b) throws Exception {
Matcher m = pmatcher(a);
if (!mmatches())
throw new Exception();
int y1 = IntegerparseInt(mgroup(1));
int m1 = IntegerparseInt(mgroup(2));
int d1 = IntegerparseInt(mgroup(3));
m = pmatcher(b);
if (!mmatches())
throw new Exception();
int y2 = IntegerparseInt(mgroup(1));
int m2 = IntegerparseInt(mgroup(2));
int d2 = IntegerparseInt(mgroup(3));
return 相差天数(y1, m1, d1, y2, m2, d2);
}
public static int 相差天数(int y1, int m1, int d1, int y2, int m2, int d2) {
return 总第几天(y1, m1, d1) - 总第几天(y2, m2, d2);
}
public static int 总第几天(int y, int m, int d) {
int a = (y - 1) 365 + (y - 1) / 4 - (y - 1) / 100 + (y - 1) / 400;
return a + 年第几天(y, m, d);
}
public static int 年第几天(int y, int m, int d) {
return 闰年(y) 润年月前天数[m] + d : 平年月前天数[m] + d;
}
public static boolean 闰年(int 年) {
return 年 % 400 == 0 || (年 % 4 == 0 && 年 % 100 != 0);
}
private static final int[] 平年月天数 = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
private static final int[] 平年月前天数 = new int[14], 润年月前天数 = new int[14];
static {
int n = 0;
for (int i = 1; i <= 12; i++) {
平年月前天数[i] = n;
润年月前天数[i] = i > 2 n + 1 : n;
n += 平年月天数[i];
}
平年月前天数[13] = n;
润年月前天数[13] = n + 1;
}
}
public int[] getLeapYear(int beginYear, int endYear) {
int[] arr = new int[endYear-beginYear];
for (int i = 0; beginYear < endYear; beginYear++,i++) {
if ((beginYear % 4 == 0 && beginYear % 100 != 0) || beginYear % 400 == 0) {
arr[i] = beginYear;
Systemoutprintln(beginYear + "是闰年");
}
else
Systemoutprintln(beginYear + "是平年");
}
return arr;
}
代码写的不怎么样,但基本能实现你的要求
以上就是关于java闰年问题全部的内容,包括:java闰年问题、怎样用JAVA写判断一个年份是不是闰年的程序、大神求助 用JAVA编写一个程序,显示从101到2100 期间所有的闰年,每行显示10个。数字之间用一个空格字等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)