本帖最後由 tonyh 於 2016-8-12 20:30 編輯
- import java.util.*;
- public class JPA01
- {
- static Scanner s = new Scanner(System.in);
- public static void main(String[] args)
- {
- Scanner s=new Scanner(System.in);
- int p,q,sum=0;
- String name[]={"遙控飛機","汽車模型","球棒 ","機器人","玩具槍 ","各式玩偶","電動"};
- int price[]={1000,80,1450,1950,1500,65,550};
- System.out.println("~~~~~~有趣玩具店~~~~~~");
- System.out.println("商品價目表:");
- for(int i=0;i<7;i++)
- {
- System.out.println((i+1)+"."+name[i]+"\t"+price[i]+"元");
- }
- System.out.println("8.結帳");
- for(;;)
- {
- System.out.print("請輸入商品代碼:");
- p=s.nextInt();
- if(p==8)
- {
- break;
- }
- else if(p>=1 && p<=7)
- {
- System.out.print("數量:");
- q=s.nextInt();
- if(q<=0)
- {
- System.out.println("輸入錯誤!");
- continue;
- }
- sum+=(price[p-1]*q);
- }
- else
- {
- System.out.println("輸入錯誤!");
- continue;
- }
- }
- System.out.print("總共 "+sum+"元");
- }
-
-
- }
複製代碼 |