|
@@ -0,0 +1,110 @@
|
|
|
|
+/**
|
|
|
|
+ * ClassName: HomeWork
|
|
|
|
+ *
|
|
|
|
+ * @Author 爱扣钉-陈晨
|
|
|
|
+ * @Create 2023/11/17 16:24
|
|
|
|
+ * @Version 1.0
|
|
|
|
+ */
|
|
|
|
+public class HomeWork {
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ int year = 2001;
|
|
|
|
+ int month = 2;
|
|
|
|
+ int days = 28;
|
|
|
|
+
|
|
|
|
+ if (year >= 0){
|
|
|
|
+ if (month >= 1 && month <= 12){
|
|
|
|
+ //标识 每月天数最大值
|
|
|
|
+ int maxDay;
|
|
|
|
+
|
|
|
|
+ if ( month == 4 || month == 6 || month == 9 || month == 11 ){
|
|
|
|
+ //day 最大值 范围 0 - 30
|
|
|
|
+ maxDay = 30;
|
|
|
|
+ } else if ( month == 2 ){
|
|
|
|
+ //day 最大值 范围 0 - 28 29
|
|
|
|
+ maxDay = 28;
|
|
|
|
+ if ( year % 4 == 0 && year % 100 != 0 || year % 400 == 0){
|
|
|
|
+ maxDay++;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //day 最大值 范围 0 - 31
|
|
|
|
+ maxDay = 31;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (days >= 0 && days <= maxDay){
|
|
|
|
+ //符合
|
|
|
|
+ System.out.println(year+"年"+month+"月"+days+"日");
|
|
|
|
+ }else{
|
|
|
|
+ System.out.println("天数不符合");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }else {
|
|
|
|
+ System.out.println("月份不符合");
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ System.out.println("年分不符合");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ x = 40 y = 20 z = 30;
|
|
|
|
+
|
|
|
|
+ 定义三个整数变量. 按顺序输出 变量的大小.从小到大. 输入 xyz 的值。
|
|
|
|
+
|
|
|
|
+ 输出值
|
|
|
|
+ x:10 > y :20 > z: 30;
|
|
|
|
+ y:20 > z:30 > x:40
|
|
|
|
+
|
|
|
|
+ */
|
|
|
|
+ public static void main2(String[] args) {
|
|
|
|
+ int num1 = 40;
|
|
|
|
+ int num2 = 60;
|
|
|
|
+ int num3 = 30;
|
|
|
|
+
|
|
|
|
+ if ( num1 > num2 ){
|
|
|
|
+ int temp = num1;
|
|
|
|
+ num1 = num2;
|
|
|
|
+ num2 = temp;
|
|
|
|
+ }
|
|
|
|
+ if ( num2 > num3 ){
|
|
|
|
+ int temp = num2;
|
|
|
|
+ num2 = num3;
|
|
|
|
+ num3 = temp;
|
|
|
|
+ }
|
|
|
|
+ if ( num1 > num2 ){
|
|
|
|
+ int temp = num1;
|
|
|
|
+ num1 = num2;
|
|
|
|
+ num2 = temp;
|
|
|
|
+ }
|
|
|
|
+ System.out.println("num1:"+ num1 + "> num2 :"+num2 +" > num3 :"+num3);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ 定义两个变量 a 和 b。
|
|
|
|
+
|
|
|
|
+ 如果 a > b 交换 a 和 b 的值。 输出 a 和 b
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ public static void main1(String[] args) {
|
|
|
|
+ int a = 30;
|
|
|
|
+ int b = 20;
|
|
|
|
+
|
|
|
|
+ System.out.println("a:"+a);
|
|
|
|
+ System.out.println("b:"+b);
|
|
|
|
+
|
|
|
|
+ if (a > b){
|
|
|
|
+ // 交换 临时变量
|
|
|
|
+ int temp = a;
|
|
|
|
+ a = b;
|
|
|
|
+ b = temp;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ System.out.println("a:"+a);
|
|
|
|
+ System.out.println("b:"+b);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|