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);
         }
    }
}
全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务