코딩테스트/자바 코딩테스트
예금, 출금, 조회, 종료 프로그램 만들기
Samsun
2023. 9. 11. 10:56
반응형
문제
문제 풀이
더보기
int balance = 0;
Scanner scan = new Scanner(System.in);
while (true) {
System.out.println("-------------------");
System.out.print("1.예금 | 2.출금 | 3.잔고 | 4.종료");
System.out.println("-------------------");
System.out.print("선택> ");
String choice = scan.nextLine();
if ("1".equals(choice)) {
System.out.print("예금액> ");
int price = Integer.parseInt(scan.nextLine());
balance += price;
} else if ("2".equals(choice)) {
System.out.print("출금액> ");
int price = Integer.parseInt(scan.nextLine());
balance -= price;
} else if ("3".equals(choice)) {
System.out.println("잔고> "+balance);
} else if ("4".equals(choice)) {
System.out.print("프로그램 종료");
}
}