2021-02-09 Chapter3_11 Chapter3_12

import java.util.Scanner;

public class Chapter3_11 {
    public static void main(String[] args) {
        System.out.println("Enter the month: ");
        Scanner input = new Scanner(System.in);
        int month = input.nextInt();
        System.out.println("Enter the year: ");
        int year = input.nextInt();

        switch (month) {
            case 1:
                System.out.println("January" + " " + year + " has 31 days");break;
            case 2:
                if((year % 4 == 0 && year % 100 != 0 ) || year % 400 == 0)
                    System.out.println("February" + " " + year + " has 29 days ");
                else
                    System.out.println("February" + " " + year + " has 28 days ");
                break;
            case 3:
                System.out.println("March" + " " + year + " has 31 days");break;
            case 4:
                System.out.println("April" + " " + year + " has 30 days");break;
            case 5:
                System.out.println("May" + " " + year + " has 31 days");break;
            case 6:
                System.out.println("June" + " " + year + " has 30 days");break;
            case 7:
                System.out.println("July" + " " + year + " has 31 days");break;
            case 8:
                System.out.println("August" + " " + year + " has 31 days");break;
            case 9:
                System.out.println("September" + " " + year + " has 30 days");break;
            case 10:
                System.out.println("October" + " " + year + " has 31 days");break;
            case 11:
                System.out.println("November" + " " + year + " has 30 days");break;
            case 12:
                System.out.println("December" + " " + year + " has 31 days");break;


        }
        input.close();


    }
}

2021-02-09 Chapter3_11 Chapter3_12

import java.util.Scanner;

public class Chapter3_12 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter a three-digit integer: ");
        int num = input.nextInt();
        if (num / 100 == num % 10)
            System.out.println(num + " is a palinderome");
        else
            System.out.println(num + " is not a palinderome");
    }
}

 

2021-02-09 Chapter3_11 Chapter3_12

上一篇:Python 运算符和表达式 https://www.lanqiao.cn/courses/596/learning/?id=2038


下一篇:Java计算2个时间单位计算相差多少天