import java.util.Scanner;
public class stack_practice {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s= new Scanner(System.in);
char[] stack = new char[5];
int top=0;
char makarong='A';
int choice=4;
while(choice!=3){
System.out.println("(1)마카롱 넣기 (2)마카롱 빼기" + "(3)종료");
choice= s.nextInt();
switch(choice){
case 1:
if(top>=5){
System.out.println("유리통이 꽉 차서 안들어 감");
}else{
stack[top]=makarong++;
System.out.printf("마카롱 %c가 유리통에 들어감\n", stack[top]);
top++;
}
break;
case 2:
if(top<=0){
System.out.println("더이상 마카롱이 없음");
}else{
top--;
System.out.printf("마카롱 %c가 유리통에서 나옴\n", stack[top]);
stack[top]=' ';
}
break;
case 3:
System.out.printf("현재 유리통에 마카롱 %d 개 있음.\n", top);
System.out.printf("스택 프로그램 종료\n");
break;
default:
System.out.println("다른 값을 입력하세요.");
}
}
}
}
댓글
댓글 쓰기