设计思路:没什么思路,知道书买多了的规律,还是很好做的。
package time1;
import java.util.InputMismatchException;
import java.util.Scanner;
public class book02 {
public static void main(String[] args)
{
int bookNum = 0;
double money = 0;
Scanner sc = new Scanner(System.in);
System.out.println("请输入您要买的书的数量:");
try{
bookNum = sc.nextInt();
}
catch(InputMismatchException e)
{
System.out.println("你的输入有误");
}
if(bookNum == 3)
{
money = 21.6;
}
else if(bookNum % 5 == 3)
{
money = bookNum*8 - ((bookNum - 8)%5)*10 - 12.8;
}
else if(bookNum % 5 == 1)
{
money = (bookNum/5)*30 + 8;
}
else if(bookNum % 5 == 2)
{
money = (bookNum/5)*30 + 15.2;
}
else if(bookNum % 5 == 4)
{
money = (bookNum/5)*30 + 25.6;
}
else if(bookNum % 5 == 0)
{
money = (bookNum/5)*30;
}
System.out.println("书价最便宜是:"+money);
}
}