题解 | #计算商场折扣#
计算商场折扣
https://www.nowcoder.com/practice/cf4dcda7bf974f83afe38af4b14946a7
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int i1 = in.nextInt(); if (i1 < 100) { System.out.println(i1); } else if (i1 < 500) { i1 = (int)(i1 *0.9);//0.9默认为double类型与i1做运算后,(i1*0.9)变为double类型, //此时应该进行强制类型转换。 System.out.println(i1); } else if (i1 < 2000 ) { i1 = (int)(i1 * 0.8); System.out.println(i1); } else if (i1 < 5000 ) { i1 = (int)(i1 * 0.7); System.out.println(i1); } else { i1 = (int)(i1 * 0.6); System.out.println(i1); } } }