java编程题练习3

版权声明:博客内容为本人自己所写,请勿转载。 https://blog.csdn.net/weixin_42805929/article/details/82193044

【程序11】
题目:有1、2、3、4四个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?

public class Test11 {
    public static void main(String[] args) {
        int count = 0;
        for (int x = 1; x < 5; x++) {
            for (int y = 1; y < 5; y++) {
                for (int z = 1; z < 5; z++) {
                    if (x != y && y != z && x != z) {
                        count++;
                        System.out.print(x * 100 + y * 10 + z+" ");
                    }
                }
            }
        }
        System.out.println();
        System.out.println("共有" + count + "个三位数");
    }
}

【程序12】
题目:企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元的部分按1%提成,从键盘输入当月利润,求应发放奖金总数?

import java.util.Scanner;

public class Test12 {
    @SuppressWarnings("resource")
    public static void main(String[] args) {
        double reward = 0;
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入当月的利润(万元):");
        Double d = sc.nextDouble();
        if(d > 0 && d <= 10) {
            reward = d * 0.1;
        }else if (d > 10 && d <= 20) {
            reward = 10 * 0.1+(d-10)*0.075;
        }else if (d > 20 && d <= 40) {
            reward = 10 * 0.1+(20-10)*0.075+(d-20)*0.05;
        }else if (d > 40 && d <= 60) {
            reward = 10 * 0.1+(20-10)*0.075+(40-20)*0.05+(d-40)*0.03;
        }else if (d > 60 && d <= 100) {
            reward = 10 * 0.1+(20-10)*0.075+(40-20)*0.05+(60-40)*0.03+(d-60)*0.015;
        }else if(d > 100){
            reward = 10 * 0.1+(20-10)*0.075+(40-20)*0.05+(60-40)*0.03+(100-60)*0.15+(d-100)*0.01;
        }
        System.out.println("应发放奖金总数:"+reward+"万元");
    }
}

【程序13】
题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?

public class Test13 {
    public static void main(String[] args) {
        for (int i = 0; i < 10000; i++) {
            if (Math.sqrt(i+100)%1==0) {
                if(Math.sqrt(i+168)%1==0) {
                    System.out.print(i+":加上100后是一个完全平方数,再加上168又是一个完全平方数");
                }
            }
        }
    }
}

【程序14】
题目:输入某年某月某日,判断这一天是这一年的第几天?

import java.util.Scanner;

public class Test14 {
    @SuppressWarnings({ "unused", "resource" })
    public static void main(String[] args) {
        long year, month, date;
        int days = 0;
        boolean flag = true;
        Scanner sc = new Scanner(System.in);
        do {
            System.out.print("请输入年:");
            year = sc.nextLong();
            System.out.print("请输入月:");
            month = sc.nextLong();
            System.out.print("请输入日:");
            date = sc.nextLong();
            if (year < 0 || month < 0 || month > 12 || date < 0 || date > 31) {
                System.out.println("输入有误,请重新输入");
                flag = false;
            }
        } while (false);
        for (int i = 0; i < month; i++) {
            switch (i) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                days = 31;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                days = 30;
                break;
            case 2:
                if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {
                    days = 29;
                }else{
                    days = 28;
                }
                break;
            }
            date = days+date;
        }
        System.out.println(year + "-" + month + "-" + days + "是这年的第" + (date+days) + "天。");
    }
}

【程序15】
题目:输入三个整数x,y,z,请把这三个数由小到大输出。

import java.util.Scanner;

public class Test15 {
    @SuppressWarnings("resource")
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入三个整数:");
        String st = sc.nextLine();
        String[] s = st.split(" ");
        int x = 0, y = 0, z = 0, temp = 0;
        for (int i = 0; i < s.length; i++) {
            x = Integer.parseInt(s[0]);
            y = Integer.parseInt(s[1]);
            z = Integer.parseInt(s[2]);
            if (x > y) {
                temp = x;
                x = y;
                y = temp;
            }
            if (x > z) {
                temp = x;
                x = z;
                z = temp;
            }
            if (y > z) {
                temp = y;
                y = z;
                z = temp;
            }
        }
        System.out.println("三个数由小到大输出为:"+x+" "+y+" "+z);
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_42805929/article/details/82193044