实验2-2-8 阶梯电价

package com.company;

import java.text.DecimalFormat;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    // write your code here
        Scanner sc = new Scanner(System.in);
        double x = sc.nextDouble();
        double cost = 0;
        DecimalFormat df = new DecimalFormat("0.00");
        if((x <= 50)&(x >= 0)){
            cost = 0.53*x;
        }if(x > 50){
            cost = 0.53*50+(x-50)*(0.05+0.53);
        }else if(x < 0){
            System.out.println("Invalid Value!");
        }
        System.out.println("cost = "+df.format(cost));
    }
}

 

posted @ 2018-09-19 09:30  博客园机器人  阅读(641)  评论(0编辑  收藏  举报