JAVA基础练习题 代码1

       题目:电话计费器,输入通话秒数,按分钟计费。(每分钟0.5元)

public class E01_01电话计费器 {

	public static void main(String[] args) {
		Scanner number = new Scanner(System.in);
		System.out.println("请输入通话秒数:");
		double num = number.nextInt();
		
		double cost = 0;
		if(num%60 == 0 ){
			cost = num/60*0.5;
		}else{
			cost = (int)(num/60+1)*0.5;
		}
		
		System.out.printf("本次通话花费%.2f元",cost);
		number.close();
	}
}

题目:的士计价器(西安市的出租车,起步(2公里以内)价为7元,超过2公里按照每公里3元计算)

public class E01_02的士计费器 { public static void main(String[] args) { Scanner number = new Scanner(System.in); System.out.print("请输入路程:"); double journey = number.nextDouble(); double money = 0; if(journey <= 2){ System.out.println("本次行程花费为7元"); }else{ money = (journey-2)*3+7; System.out.printf("本次行程花费为%.2f元",money); } number.close(); } }

级数

应纳税所得额(含税)

税率(%)

速算扣除数

1

不超过1500元的

3

0

2

超过1500元至4,500元的部分

10

105

3

超过4,500元至9,000元的部分

20

555

4

超过9,000元至35,000元的部分

25

1,005

5

超过35,000元至55,000元的部分

30

2,755

6

超过55,000元至80,000元的部分

35

5,505

7

超过80,000元的部分

45

13,505

计算公式:

缴税=全月应纳税所得额*税率-速算扣除数

全月应纳税所得额=(应发工资-四金)3500

实发工资=应发工资-四金-缴税

假设四金700元,3500元为起征点,要求输入工资,输出个人所得税和实发工资

public class E01_03个税计算器 {

	public static void main(String[] args) {
		Scanner number = new Scanner(System.in);
		System.out.print("请输入应发工资:");
		double salary1 = number.nextDouble();//应发工资
		
		double salary = 0;//实发工资
		double i = (salary1-700)-3500;//全月应纳税所得额
		double tax = 0;//缴税
		
		if(i > 0){
			if(i <= 1500){
				tax = i*0.03-0;
			}else if(i<=4500){
				tax = i*0.1-105;
			}else if(i<=9500){
				tax = i*0.2-555;
			}else if(i<=35000){
				tax = i*0.25-1005;
			}else if(i <=55000){
				tax = i*0.3-2755;
			}else if(i<=80000){
				tax = i*0.35-5505;
				
			}else{
				tax = i*0.45-13505;
			}
			salary = salary1-700-tax;
			
			System.out.printf("个人所得税为%.2f元,实际所发工资为%.2f元",tax,salary);
		}else{
			salary = salary1-700;
			System.out.printf("个人所得税为0元,实际所发工资为%.2f元",salary);
		}
		number.close();
	}
}

       题目:根据性别和体重计算输血量。女性体重不超过50kg的输血量为200毫升,否则250毫升;男性不超过60kg的输血量为250毫升,否则300毫升。


public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.print("请输入性别:");
		String sex = input.next();//接收性别
		System.out.print("请输入体重:");
		double weight = input.nextDouble();
		
		int blood = 0;
		if(sex.equals("男")){
			if(weight <= 60){
				blood = 250;
			}else{
				blood = 300;
			}
		}else{
			if(weight <= 50){
				blood = 200;
			}else{
				blood = 250;
			}
		}
		System.out.printf("输血量为%d毫升",blood);
		input.close();
	}
}

public class E01_完数判断 {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.print("请输入一个整数:");
		int number = input.nextInt();
		
		int sum = 0;//因子和
		for(double i = 1;i < number/2;i++){
			if(number%i == 0){
				sum += i;
			}
		}
		System.out.printf("%d%s完数",number,sum==number?"是":"不是");
		
	}

}

public class E01_中美经济赶超 {

	public static void main(String[] args) {
		double china = 49089.82;
		double usa = 142562.75;
		
		int year = 2009;
		while(china < usa){
			china += china*0.08;//china *= (1+0.08)
			usa += usa*0.02;//usa *= (1+0.02)
			year ++;
		}
		System.out.printf("第%d年中国经济赶超美国。",year);
	}

}



你可能感兴趣的:(Java,基础,程序,代码,学习笔记)