商场打折促销活动程序编写

已知某商场进行促销活动,对于消费的价格有折扣活动,即消费1000元打9折;消 费2000元打8.5折;消费3000元打7折;消费5000元打6折。编写程序求出消费者实 际的消费。用Java编写

你可以使用if条件语句来写也可以使用switch分支语句都一样,使用if语句代码如下

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int price=scanner.nextInt();
        if(price>=5000){
            System.out.println("实际消费价格:"+price*0.6);
        }else if(price>=3000){
            System.out.println("实际消费价格:"+price*0.7);
        }
        else if(price>=2000){
            System.out.println("实际消费价格:"+price*0.85);
        }
        else if(price>=1000){
            System.out.println("实际消费价格:"+price*0.9);
        }
        else{
            System.out.println("实际消费价格:"+price);
        }
    }
}

img

switch