博客
关于我
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/

    你可能感兴趣的文章
    param[:]=param-lr*param.grad/batch_size的理解
    查看>>
    spring mvc excludePathPatterns失效 如何解决spring拦截器失效 excludePathPatterns忽略失效 拦截器失效 spring免验证拦截器不起作用
    查看>>
    Spring Cloud 之注册中心 EurekaServerAutoConfiguration源码分析
    查看>>
    Parrot OS 6.2 重磅发布!推出全新 Docker 容器启动器
    查看>>
    Parrot OS 6.3 发布!全面提升安全性,新增先进工具,带来更高性能
    查看>>
    ParseChat应用源码ios版
    查看>>
    Part 2异常和错误
    查看>>
    Pascal Script
    查看>>
    Spring Boot集成Redis实现keyspace监听 | Spring Cloud 34
    查看>>
    Spring Boot中的自定义事件详解与实战
    查看>>
    Passport 密码模式
    查看>>
    Spring Boot(七十六):集成Redisson实现布隆过滤器(Bloom Filter)
    查看>>
    passwd命令限制用户密码到期时间
    查看>>
    Spring Boot 动态加载jar包,动态配置太强了!
    查看>>
    Spring @Async执行异步方法的简单使用
    查看>>
    PAT (Basic Level) Practice 乙级1021-1030
    查看>>
    PAT (Basic Level) Practice 乙级1031-1040
    查看>>
    PAT (Basic Level) Practice 乙级1041-1045
    查看>>
    SparkSql的元数据
    查看>>
    PAT (Basic Level) Practice 乙级1051-1055
    查看>>