/** * Title: Demo06_if分支结构.java * @author Mr.Seven * @date 2020年9月2日 * @version 1.0 */ package cn.tedu.day902;
//商品打折 import java.util.Scanner;
public class Demo06_if分支结构 { public static void main(String[] args) { // while(true) { System.out.println("请输入商品总价:"); Scanner sc = new Scanner(System.in); double m = sc.nextDouble(); double m1 = m; if (m >= 0 && m < 1000) { System.out.println("商品总价:" + m + "元\n" + "折扣:0.00\n应付:" + m + "元");
} else if (m >= 1000 && m < 2000) { m1 = m * 0.9; System.out.println("商品总价:" + m + "元\n" + "折扣:-" + 0.1 * m + "元(九折)\n应付:" + m1 + "元"); } else if (m >= 2000 && m < 5000) { m1 = m * 0.8; System.out.println("商品总价:" + m + "元\n" + "折扣:-" + 0.2 * m + "元(八折)\n应付:" + m1 + "元"); } else if (m >= 5000) { m1 = m * 0.5; System.out.println("商品总价:" + m + "元\n" + "折扣:-" + 0.5 * m + "元(五折)\n应付:" + m1 + "元"); } else { System.out.println("请输入正确的总价!\n"); }
sc.close(); } }