Java/이것이자바다

이것이 자바다 4장 확인문제 7번

유호야 2020. 10. 8. 11:39
반응형

if문을 이용

import java.util.Scanner;

public class add {

	public static void main(String[] args) {

		boolean run = true;
		
		Scanner scanner = new Scanner(System.in);
		
		int balance = 0;
		
		while(run) {
			System.out.println("--------------");
			System.out.println("1.예금 2.출금 3.잔고 4.종료");
			System.out.println("--------------");
			System.out.print("선택 > ");
			String value = scanner.nextLine();
			if(value.equals("1")) {
				System.out.println("예금액> 10000");
			}
			if(value.equals("2")) {
				System.out.println("출금액> 2000");
			}
			if(value.equals("3")) {
				System.out.println("잔액> 8000");
			}
			if(value.equals("4")) {
				System.out.println("프로그램 종료");
				break;
			}
			
		}
		
		
		
	}
	
	

}

 

switch문을 이용

import java.util.Scanner;

public class scanner {

	public static void main(String[] args) {

		boolean run = true;
		
		Scanner scanner = new Scanner(System.in);
		
		int balance = 0;
		
		while(run) {
			System.out.println("--------------");
			System.out.println("1.예금 2.출금 3.잔고 4.종료");
			System.out.println("--------------");
			System.out.print("선택 > ");
			String value = scanner.nextLine();
				switch(value) {
				case "1" :
					System.out.println("예금액> 10000");
					break;
				case "2" :
					System.out.println("출금액> 2000");
					break;
				case "3" :
					 System.out.println("잔액> 8000");
					 break;
				case "4" :
					 
					 break;
				}
				System.out.println("프로그램 종료");
			
		}
		
		
		
	}
	
	

}
반응형