题目: 循环输入年份,判断年份如果为闰年则结束循环,最后输出闰年年份 考察:循环结构、break关键字
package Pack2; import java.util.Scanner; public class Test2 { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("请输入年份"); int year = in.nextInt(); if (year % 4 ==0){ if (year%100 !=0){ System.out.println(year+"是闰年"); }else if (year % 400 ==0){ System.out.println(year+"是平年"); }else { System.out.println(year+"不是闰年"); } }else if (year % 400 ==0){ System.out.println(year+"是闰年"); }else { System.out.println(year+"是平年"); } } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)