Java实现 洛谷 P1422 小玉家的电费

在这里插入图片描述

import java.util.*;
public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner (System.in);
		
		int ele = in.nextInt();
		double out;
		
		
		if (ele <= 150) 
		{
			out = 0.4463*ele;
		}
		
		else if ((150 < ele) && (ele <= 400))
		{
			out = 66.945 + 0.4663 * (ele - 150);
		}
		
		else 
		{
			out = 150*0.4463 + 250*0.4663 + (ele - 400)*0.5663;
		}
	
		System.out.println(String.format("%.1f", out));
	
	
	}

}
posted @ 2019-07-30 19:24  南墙1  阅读(25)  评论(0编辑  收藏  举报