题解 | #计算商场折扣#

计算商场折扣

http://www.nowcoder.com/practice/cf4dcda7bf974f83afe38af4b14946a7

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int price = console.nextInt();
        int cost = 0;

        //write your code here......
        if (price >= 5000) {
//             6折
            cost = (int) (price*0.6);
        } else if(price >= 2000 && price < 5000) {
//             7折
            cost = (int) (price*0.7);
        } else if(price >= 500 && price < 2000) {
//             8折
            cost = (int) (price*0.8);
        } else if(price >= 100 && price < 500){
//             9折
            cost = (int) (price*0.9);
        } else {
//             不打折
            cost = (int)price;
        }

        System.out.println(cost);
    }
}

double 转为 int :

  • (int)double 直接舍去小数。
  • Math.round(double) 四舍五入
  • Math.ceil(double) 向上取整
  • Math.floor(doubel) 向下取整
全部评论

相关推荐

牛客37185681...:马德,我感觉这是我面过最恶心的公司,一面是两个女hr,说什么实习前几个月属于试用期,试用期过了才能转成正式实习生,我***笑了,问待遇就是不说,问能不能接受全栈,沙币公司
如果可以选,你最想去哪家...
点赞 评论 收藏
分享
牛客96763241...:杭电✌️也是打完招呼,没人回吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务