java编程题练习3

【程序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);
	}
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值