作业帮 > 综合 > 作业

A leap year is a year with 366 days.A leap year has the 29th

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/14 17:15:46
A leap year is a year with 366 days.A leap year has the 29th February.A year is a leap year if it is divisible by 4 except for
the century years (divisible by 100).Century years are only leap years if they are divisible by 400.Write a program that
accepts a year and determines if it is a leap year.
\x05\x05\x05\x05
\x05\x05\x05
\x05\x05\x05
\x05\x05\x05\x05
\x05\x05\x05\x05\x05
Use a separate method to test if a year is a leap year.
my answer:
import java.util.Scanner;
public class JavaApplication24 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.print("Enter a year:");
int a=input.nextInt();
if((a is divisible by 4 || a is divisible by 400)){
System.out.println("a");
}else {
System.out.println("a is not a leap year");
}}
}
运行不出来?
a is divisible by 4 || a is divisible by 400)
改成
a%4==0 || a %400==0
再问: 谢谢!!!!!这样就可以了!!!为什么啊???
再答: a is divisible by 4 || a is divisible by 400

这不是英语作文,,你这不是java的语法。%在java中代表模。即除以后的余数