标签:
本数 折扣
2 5%
3 10%
4 20%
5 25%
import java.util.Scanner;
public class BuyBook {
public static void main(String[] args) {
// TODO Auto-generated method stub
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
System.out.println("请输入需要购买书本的数量:");
int booknumber = sc.nextInt();
int num=booknumber%5;//除5求余数
double price=0;
switch(num)
{
case 0://买的数量刚好为5的倍数
price=booknumber*8*0.75;
break;
case 1://买的数量除5余1
price=(booknumber-1)*8*0.75+8;
break;
case 2://买的数量除5余2
price=(booknumber-2)*8*0.75+2*8*0.95;
case 3://买的数量除5余3
if(booknumber==3)
{
price=3*8*0.9;
}
else
{
price=(booknumber-8)*8*0.75+2*4*8*0.8;
}
break;
case 4://买的数量除5余4
price=(booknumber-4)*8*0.75+4*8*0.8;
break;
}
System.out.println("购书的最低价格为"+price);
}
}
标签:
原文地址:http://www.cnblogs.com/maplely/p/5557459.html