2026第九期作业
2026第九期作业
请叫我,大叔_作业
demo01-2026-08-09作业
demo02-2026-08-10作业
demo03-2026-08-10打印输出学生信息
demo04-2026-08-10去掉控制台最后的,(2)输入参数实现对平闰年的判断
demo05-2026-08-10改造如下程序,优化:(1)在用户输入后判断操作符的合法性【只能输入1-4】(2)优化计算器能够兼容所有的数,而不是只有整数
MS08067安全实验室
-
+
首页
demo04-2026-08-10去掉控制台最后的,(2)输入参数实现对平闰年的判断
package JAVASE; import java.util.Scanner; //2026-08-10去掉控制台最后的,(2)输入参数实现对平闰年的判断 public class demo04 { private int day; private int month; private int year; public static void printInfo(int flag, int i){ for(int j = 1; j <= flag; j++){ if(j == flag){ System.out.print(i + "月" + j + "日"); System.out.println("\n"); }else { System.out.print(i + "月" + j + "日" + ","); } } // switch (flag){ // case 28: // for (int j = 1; j <= 28; j++) { // if(j==28){ // System.out.print(i + "月" + j + "日"); // }else { // System.out.print(i + "月" + j + "日" + ","); // } // } // break; // case 29: // for (int j = 1; j <= 29; j++) { // if(j==29){ // System.out.print(i + "月" + j + "日"); // }else { // System.out.print(i + "月" + j + "日" + ","); // } // } // break; // case 30: // for (int j = 1; j <= 30; j++) { // if(j==30){ // System.out.print(i + "月" + j + "日"); // }else { // System.out.print(i + "月" + j + "日" + ","); // } // } // break; // case 31: // for (int j = 1; j <= 31; j++) { // if(j==31){ // System.out.print(i + "月" + j + "日"); // }else { // System.out.print(i + "月" + j + "日" + ","); // } // } // break; // } } public static void main(String[] args) { System.out.println("请输入年份:"); Scanner scanner = new Scanner(System.in); int year = scanner.nextInt(); Boolean yearBolean = YearDay(year); if(yearBolean){ System.out.println("输入的年份为闰年!!!"); }else { System.out.println("输入的年份为不是闰年!!!"); } // boolean result = false; for (int i = 1; i <= 12; i++) { if (i == 1 || i == 3 ||i == 5 ||i == 7 ||i == 8 ||i == 10 ||i == 12){ printInfo(31,i); System.out.println(); } else if(i == 2) { if (yearBolean == false){ printInfo(28,i); System.out.println(); }else { printInfo(29,i); System.out.println(); } }else { printInfo(30,i); System.out.println(); } } scanner.close(); } public static boolean YearDay(int yaer){ boolean day =false; if(yaer % 4 == 0){ day =true; } return day; } }
piscesguardian01
2026年8月14日 17:22
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
PDF文档
PDF文档(打印)
分享
链接
类型
密码
更新密码