返回列表 發帖
  1. package hi87;

  2. public class hi78 {

  3.         public static void main(String[] args) {
  4.                 // TODO 自動產生的方法 Stub
  5. int hours=0;

  6. hours=2;
  7. park(hours);
  8. System.out.println("");
  9. hours=3;
  10. park(hours);
  11. System.out.println("");

  12. hours=5;
  13. park(hours);
  14. System.out.println("");
  15. hours=8;
  16. park(hours);
  17.         }




  18. public static void park(int hours)
  19. {
  20. int[]hourTable={0,2,4,6};
  21. int[] feetable={30,50,80,100};
  22. int fee=0;

  23. System.out.println("停車時數:"+hours+"小時");
  24.         for(int a=3;a>=0;a--)
  25.         {
  26.                 if(hours>hourTable[a])
  27.                 {
  28.                         fee+=(hours-hourTable[a])*feetable[a];
  29.                         hours=hourTable[a];
  30.                 }
  31.                
  32.                
  33.                
  34.                
  35.         }
  36. System.out.println("應繳費用"+fee+"元整");

  37. }
  38. }
複製代碼
張閎鈞OuO

TOP

返回列表