栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java学习02

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java学习02

Java学习第二章 数据类型与运算符

课后习题

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);
    }
}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/756536.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号