题解 | #计算商场折扣#

计算商场折扣

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>0&&price<100){
        cost+=price;
    }else if(price>=100&&price<500){
        cost+=(int)price*0.9;
    }else if(price>=500&&price<2000){
        cost+=(int)price*0.8;
    }else if(price>=2000&&price<5000){
        cost+=(int)price*0.7;
    }else if(price>=5000){
        cost+=(int)price*0.6;
    }
    System.out.println(cost);
}

}

就是一道分类使用if选择判断的条件语句,在每个价格不同的段位强转一次就可以了

全部评论

相关推荐

07-11 10:56
门头沟学院 Java
码客明:大胆的说自己能实习6个月就行
点赞 评论 收藏
分享
点赞 评论 收藏
分享
fRank1e:吓得我不敢去外包了,但是目前也只有外包这一个实习,我还要继续去吗
点赞 评论 收藏
分享
想按时下班的大菠萝在...:隔壁学校的,加油多投, 实在不好找可以下个学期开学找,把算法八股准备好,项目有空再换换
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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