• 입력받는 번호에 따라 다른 기능을 출력하기
(1) 스캐너로 번호 입력받기
Scanner scanner= new Scanner(System.in);
(2) 삼항연산자 이용
result=(a=1)? true:false;
pacakage day005
import java.util.Scanner; 
public class Miniproject { 
 public static void main(String[]args) { 
   
  //변수 
  int a=0; 
  String result="";   
   
  Scanner scanner= new Scanner(System.in); 
   
  //입력 
  System.out.print("=======BANK=======\r\n" 
    + "1. 추가\r\n"+ "2. 조회\r\n"+ "3. 입금\r\n" 
    +"4. 출금\r\n"+"5. 삭제\r\n"+"9. 종료\r\n" 
    +"입력>>>");  a= scanner.nextInt(); 
  //처리 
  (result = a==1) ? "추가": 
  (result = a==2) ? "조회":
  (result = a==3) ? "입금":
  (result = a==4) ? "출금":
  (result = a==5) ? "삭제":
  (result = a==9) ? "종료":"" ;  

  //출력  
  System.out.println(result+ "기능 입니다."); 
      } 
}​

'Java_BANK 프로젝트' 카테고리의 다른 글

MINIBANK5  (0) 2022.07.14
MINIBANK4  (0) 2022.07.14
MINIBANK3  (0) 2022.07.14
MINIBANK2  (0) 2022.07.14

+ Recent posts