- package hi87;
- public class hi78 {
- public static void main(String[] args) {
- // TODO 自動產生的方法 Stub
- int hours=0;
- hours=2;
- park(hours);
- System.out.println("");
- hours=3;
- park(hours);
- System.out.println("");
- hours=5;
- park(hours);
- System.out.println("");
- hours=8;
- park(hours);
- }
- public static void park(int hours)
- {
- int[]hourTable={0,2,4,6};
- int[] feetable={30,50,80,100};
- int fee=0;
- System.out.println("停車時數:"+hours+"小時");
- for(int a=3;a>=0;a--)
- {
- if(hours>hourTable[a])
- {
- fee+=(hours-hourTable[a])*feetable[a];
- hours=hourTable[a];
- }
-
-
-
-
- }
- System.out.println("應繳費用"+fee+"元整");
- }
- }
複製代碼 |