课后习题
1、商场为员工提供了基本工资,物价津贴及房租津贴。其中,物价津贴为基本工资的40%,房屋津贴为基本工资的25%。要求:从控制台输入基本工资,并计算输出实领工资。2、小明左右手分别拿两张纸牌:黑桃10和红心8,现在交换手中的牌。编写一个程序模拟这一个过程:两个整数分别保存在两个变量中,将这两个变量的值互换,并输出互换后的结果。3、银行提供了整存整取定期存储业务,其存取分为一年、二年、三年、五年,到期凭存单支取本息。
课后习题 1、商场为员工提供了基本工资,物价津贴及房租津贴。其中,物价津贴为基本工资的40%,房屋津贴为基本工资的25%。要求:从控制台输入基本工资,并计算输出实领工资。输出结果如图所示
编写代码:
import java.util.Scanner;
public class salary {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入基本工资:");
double salary = sc.nextDouble();
double price = salary * 0.4;
double rent = salary * 0.25;
double pay = salary + price + rent;
System.out.println("该员工的工资细目为:");
System.out.println("基本工资为:" + salary);
System.out.println("物价津贴为:" + price);
System.out.println("房租津贴为:" + rent);
System.out.println("员工薪水是:" + pay);
}
}
2、小明左右手分别拿两张纸牌:黑桃10和红心8,现在交换手中的牌。编写一个程序模拟这一个过程:两个整数分别保存在两个变量中,将这两个变量的值互换,并输出互换后的结果。
结果如图所示
编写代码:
public class ChangeCard {
public static void main(String[] args) {
System.out.println("输出互换前手中的纸牌:");
int left = 10;
int right=8;
int i=0;
System.out.println("左手中的纸牌:"+left);
System.out.println("右手中的纸牌:"+right);
System.out.println("n输出互换后手中的纸牌:");
i=left;
left=right;
right=i;
System.out.println("左手中的纸牌:"+left);
System.out.println("右手中的纸牌:"+right);
}
}
3、银行提供了整存整取定期存储业务,其存取分为一年、二年、三年、五年,到期凭存单支取本息。
代码如下:
import java.util.Scanner;
public class exe{
public static void main(String[] args) {
double money;
double Year = 0.0225; //一年年利率 2.25%
double TwoYears = 0.027; //二年年利率 2.7%
double ThreeYears = 0.0324; //三年年利率3.24%
double FiveYears = 0.036; //五年年利率3.6%
Scanner input = new Scanner(System.in);
System.out.println("请输入本金:");
money = input.nextInt();
System.out.println("本金为:" + money + "n");
//求利息(利息 = 本金 * 年利率 * 存期)
double AInterest = money * Year * 1; // 一年利益
double TwoInterest = money * TwoYears * 2; //二年利息
double ThreeInterest = money * ThreeYears * 3; //三年利息
double FiveInterest = money * FiveYears * 5; //五年利息
//求本息(本息 = 本金 + 利息)
double Aprincipal = money + AInterest; //一年本息
double Twoprincipal = money + TwoInterest; //二年本息
double Threeprincipal = money + ThreeInterest; //三年本息
double Fiveprincipal = money + FiveInterest; //五年本息
System.out.println("存取一年后的本息是:" + Aprincipal + "n");
System.out.println("存取二年后的本息是:" + Twoprincipal + "n");
System.out.println("存取三年后的本息是:" + Threeprincipal + "n");
System.out.println("存取五年后的本息是:" + Fiveprincipal);
}
}



