자바 기초: 자리 예약

김영채 (Kevin)·2020년 3월 16일
0

Java

목록 보기
6/6
post-thumbnail

자리 예약 시스템을 아주 간단하게 구현한 코드다. 시각적으로나마 (0,1,2,3,4,5,6) 어느 곳이 예약되어 있는지 보여준다.

package testprep;
import java.util.*;

public class MovieReg {

	public static void main(String[] args) {
		int seat;
		int[] list = {0,0,0,0,0,0,0,0,0,0};
		Scanner input = new Scanner(System.in);
		
		while(true) {
			System.out.println("--------------------------");
			System.out.println("0 1 2 3 4 5 6 7 8 9");
			System.out.println("--------------------------");
			for(int i=0;i<list.length;i++)
				System.out.print(list[i]+" ");
			
			System.out.println("\n");
			System.out.println("--------------------------");
			System.out.print("몇 번째 좌석을 예약하시겠습니까? ");
			seat = input.nextInt();
			
			switch(seat) {
			case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
			case 8: case 9:
				System.out.println("예약되었습니다");
				list[seat]=1;
				break;
			}
			System.out.println("\n");
		}
		

	}

}
profile
맛있는 iOS 프로그래밍

0개의 댓글