3.14java 上机作业【7.19】

7.19 购买机票

package se;
import java.util.Scanner;
public class sdf {

    public static void main(String[] args) {
    // TODO Auto-generated method stub
        boolean seat[]=new boolean[15];
        int cnt1=0,cnt2=0;
        Scanner in = new Scanner(System.in);
        System.out.printf("请输入头等舱个数,经济舱个数\n");
        int n=in.nextInt();
        int m=in.nextInt();
        while(in.hasNext())
        {
            int a=in.nextInt();
            if(a==1)
            {
                if(cnt1<n)
                {
                    cnt1++;
                    System.out.printf("the seat you bought is %d\n",cnt1);
                }
                else
                {
                    if(cnt2<m)
                    {
                        System.out.printf("If you want to be in the economy section,1 for yes,2 for no\n");;
                        int flag =in.nextInt();
                        if(flag==1)
                        {
                        cnt2++;
                        System.out.printf("the seat you bought is %d\n",cnt2+n);
                        }
                        else
                        {
                            System.out.println("Next flight leaves in 3 hours");
                        }
                    }
                    else
                    {
                        System.out.println("Next flight leaves in 3 hours");
                    }
                }
            }else
            {
                if(cnt2<m)
                {
                    cnt2++;
                    System.out.printf("the seat you bought is %d\n",cnt2+5);
                }
                else
                {
                    if(cnt1<n)
                    {
                        System.out.printf("If you want to be in the first-class section,1 for yes,2 for no\n");;
                        int flag =in.nextInt();
                        if(flag==1)
                        {
                        cnt1++;
                            System.out.printf("the seat you bought is %d\n",cnt1+n);
                        }
                        else
                        {
                            System.out.println("Next flight leaves in 3 hours");
                        }
                    }
                    else
                    {
                        System.out.println("Next flight leaves in 3 hours");
                    }
                }
            }
            System.out.printf("剩余头等舱%d,剩余经济舱%d\n", n-cnt1,m-cnt2);
         }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值