Java随堂练习-1 三个程序运用赋值、输入、输出

5 篇文章 0 订阅
5 篇文章 0 订阅
/**
 * @FIENDLMAO
 * 2021/3/24
 *
 * 小明左右手分别那两张牌:黑桃10和红心8,现在交换手中的牌。
 * 编写一个程序模拟这个过程:两个整数分别保存在两个变量中,将这两个变量的值互换,并输出互换后的结果。
 */
public class DataExchange {
    public static void main(String[] args) {
        int left = 10;  //定义变量 left 为左手
        int right = 8;  //定义变量 right 为右手
        int temp;   //temp 为临时变量,用于交换
        System.out.println("输出交换前的牌");
        System.out.println("左手中的纸牌"+left);
        System.out.println("右手中的纸牌"+right);
        temp = left;    //将left的值交给临时变量 temp
        left = right;   //将 right 的值交给 left
        right = temp;   //将临时变量 temp 的值交给 right
        System.out.println("输出交换后的牌");
        System.out.println("左手中的纸牌"+left);
        System.out.println("右手中的纸牌"+right);
    }
}


/**
 * @FIENDLMAO
 * 2021/3/24
 *
 * 商店为员工提供了基本工资、物价津贴以及房租津贴。
 * 其中,物价津贴为基本工资的40%。房租津贴为基本工资的25%。
 * 要求从控制台输入基本工资,并计算输出实领工资。
 */
public class RealWages {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in); //创建输入对象input
        double basicWage, priceAllowance, rentAllowance, wages;
        //     定义基本工资     物价津贴         房租津贴      薪水
        System.out.println("请输入基本工资:");
        basicWage = input.nextInt();    //从键盘获取整型数据给基本工资
        priceAllowance = basicWage * 0.4;
        rentAllowance= basicWage * 0.25;
        wages = basicWage + priceAllowance + rentAllowance;
        System.out.println("该员工的工资细目为:");
        System.out.println("基本工资为:" + basicWage);
        System.out.println("物价津贴为:" + priceAllowance);
        System.out.println("房租津贴为:" + rentAllowance);
        System.out.println("员工薪水是:" + wages);
    }
}
/**
 * @FIENDLMAO
 * 2021/3/24
 *
 * 银行提供了整存整取定期储蓄业务,其存期为一年、两年、三年、五年,到期凭存单支取本息。
 *  *****************
 *   * 存期 * 年利率  *
 *  *****************
 *  * 一年 *  2.25%  *
 *  *****************
 *  * 两年 *  2.7%   *
 *  *****************
 *  * 三年 *  3.24%  *
 *  *****************
 *  * 五年 *  3.6%   *
 *  *****************
 * 编写一个程序,输入存入的本金数目,
 * 计算假设存一年、两年、三年和五年,到期取款时,银行应该支付的本息分别是多少,输出结果。
 */
public class BankInterest {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        double principal;
        System.out.println("请输入本金:");
        principal = input.nextDouble();
        double oneYear = principal + (principal * 0.0225);
        double twoYears = principal + (principal * 0.027 * 2);
        double threeYears = principal + (principal * 0.0324 * 3);
        double fiveYears = principal + (principal * 0.036 * 5);
        System.out.println("本金为:" + principal);
        System.out.println("存取一年后本息是" + oneYear);
        System.out.println("存取两年后本息是" + twoYears);
        System.out.println("存取年三后本息是" + threeYears);
        System.out.println("存取五年后本息是" + fiveYears);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值