java小测试:回文测试、成绩判断、完全数判断、闰平年某月多少天、割绳子长短需多少天问题

package com.company;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        huiWenJundge(); //回文数字测试
        stuGradeJundge();   //学生成绩判断
        finalNumsJundge();  //完全数判断
        yearMonthJundge();  //闰月年,判断该年该月有多少天
        stickLengthJundge();//设有一长度为3000m的绳子,每天减去一半,问需几天时间,绳子的长度会短于5m。要求用do…while结构实现

    }

    public static void stickLengthJundge() {
        int stick=3000;
        int i=0;

        do{
            stick=stick/2;
            i++;

        }while (stick>=5);
        if(i>0){
            System.out.println("总共需要"+i+"天,"+"绳子的长度会小于5米");
        }
    }

    public static void yearMonthJundge() {
        int days=0;
        System.out.println("请先输入任意一个年份,再输入任意一个月份:");
        Scanner input=new Scanner(System.in);
        int year=input.nextInt();
        int month=input.nextInt();
        switch (month){
            case 2:
                if(year%4==0){
                    days=29;
                    break;
                }
                else {
                    days=28;
                    break;
                }

            case 4:
            case 6:
            case 9:
            case 11:
                days=30;
                break;
            default:
                days=31;
        }
        System.out.println(year+"年"+month+"月有"+days+"天");
    }

    private static void finalNumsJundge() {
        int sum = 1;
        System.out.println("请输入一个整数:");
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        for (int i = 2; i < n; i++) {
            if (n % i == 0)
                sum += i;
        }
        if (sum == n) {
            System.out.println(n + "是完全数");
        } else
            System.out.println(n + "不是完全数");
    }


    private static void stuGradeJundge() {
        String stuGrade="";
        System.out.println("请输入一个分数(0~100):");
        Scanner input=new Scanner(System.in);
        int stuScore=input.nextInt();
        switch(stuScore/10){
            case 10:
            case 9:
                stuGrade="你真棒,A等";
                break;
            case 8:
                stuGrade="不错,B等";
                break;
            case 7:
            case 6:
                stuGrade="还行吧,C等";
                break;
            default:
                stuGrade="太可惜了,D等";

        }
        System.out.println("亲的成绩"+stuScore+"评语为:"+stuGrade);
    }

    private static void huiWenJundge() {
        int num1;
        System.out.println("亲,请输入一个回文数,我们将对您的输入做检测:");
        Scanner input=new Scanner(System.in);
        num1=input.nextInt();
        int ownNum=num1;
        int newNum = 0;

        while(ownNum!=0){
            newNum=newNum*10;	//乘数
            newNum+=ownNum%10;
            ownNum/=10;
        }
        if(newNum==num1){
            System.out.println("此数"+num1+"为回文数");
        }
        else{
            System.out.println("此数"+num1+"不是回文数");
        }
    }
}

相关推荐
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页