本文共 777 字,大约阅读时间需要 2 分钟。
根据闽价电[2006]27号规定,月用电量的电费计算方式分为三个部分。具体规则如下:
编写一个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/