博客
关于我
P1422小玉家的电费(JAVA语言)
阅读量:129 次
发布时间:2019-02-27

本文共 777 字,大约阅读时间需要 2 分钟。

根据闽价电[2006]27号规定,月用电量的电费计算方式分为三个部分。具体规则如下:

  • 用电量在150千瓦时及以下的部分,每千瓦时的电费为0.4463元。
  • 用电量在151到400千瓦时的部分,前150千瓦时按0.4463元计算,超过150千瓦时的部分按0.4663元计算。
  • 用电量超过400千瓦时的部分,前400千瓦时按前述规则计算,超过400千瓦时的部分按0.5663元计算。
  • 编写一个Java程序,输入用电总计数,根据上述规则计算应缴纳的电费,并将结果保留到小数点后一位。

    代码实现如下:

    import java.util.Scanner;public class P1422 {    public static void main(String[] args) {        Scanner in = new Scanner(System.in);        int total = in.nextInt();        double fee = 0;        if (total <= 150) {            fee = total * 0.4463;        } else if (total > 150 && total <= 400) {            fee = (total - 150) * 0.4663 + 150 * 0.4463;        } else {            fee = (total - 400) * 0.5663 + 150 * 0.4463 + 250 * 0.4663;        }        System.out.printf("%.1f", fee);    }}

    程序逻辑清晰,直接根据用电量分段计算电费,输出结果保留到小数点后一位。

    转载地址:http://vgdb.baihongyu.com/

    你可能感兴趣的文章
    Struts2中使用Session的两种方法
    查看>>
    Stream API:filter、map和flatMap 的用法
    查看>>
    STM32工作笔记0032---编写跑马灯实验---寄存器版本
    查看>>
    Static--用法介绍
    查看>>
    ssm旅游信息管理系统的设计与实现bus56(程序+开题)
    查看>>
    order by rand()
    查看>>
    SSM(Spring+SpringMvc+Mybatis)整合开发笔记
    查看>>
    ViewHolder的改进写法
    查看>>
    Orderer节点启动报错解决方案:Not bootstrapping because of 3 existing channels
    查看>>
    org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement profile
    查看>>
    sql查询中 查询字段数据类型 int 与 String 出现问题
    查看>>
    org.apache.commons.beanutils.BasicDynaBean cannot be cast to ...
    查看>>
    org.apache.dubbo.common.serialize.SerializationException: com.alibaba.fastjson2.JSONException: not s
    查看>>
    sqlserver学习笔记(三)—— 为数据库添加新的用户
    查看>>
    org.apache.http.conn.HttpHostConnectException: Connection to refused
    查看>>
    org.apache.ibatis.binding.BindingException: Invalid bound statement错误一例
    查看>>
    org.apache.ibatis.exceptions.PersistenceException:
    查看>>
    org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
    查看>>
    org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
    查看>>
    org.apache.poi.hssf.util.Region
    查看>>