码迷,mamicode.com
首页 > 其他好文 > 详细

书的价钱

时间:2016-06-05 17:02:50      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

设计思路:没什么思路,知道书买多了的规律,还是很好做的。



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); } }

 

书的价钱

标签:

原文地址:http://www.cnblogs.com/nxxam/p/5561063.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!