질문)

 

이름과 생일을 입력받아서 각각 변수에 저장한뒤

생성자클래스에서 스위치문을 이용하여 출력하는 코드를 만들어야되는데 도와주세요

 

http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040202&docId=254496752&page=1#answer1

 

 

 

답변)

 

 

1. CLASS

 

import java.util.Scanner;

 

public class t15_006 {
  public static void main(String arg[]){
    info inf = new info();
    inf.sc = new Scanner(System.in);

 

    while(true){
      System.out.print("1) 입력 2) 출력 3) 종료 : ");
      int s1 = inf.sc.nextInt();
   
      switch(s1){
      case 1: inf.ifo(); break;
      case 2: inf.ofo(); break;
      case 3: System.out.println("종료!!"); return;
      }
      System.out.println();
    }
  }
}

 

class info{ 
  Scanner sc = null; 
  static String info[][] = new String[100][3];
  static int count = 1;
 
  void ofo(){
    System.out.println("번호 \t 이름 \t 생일");
    for(int i = 0; i < count; i++){
      if(info[i][0] != null){
        System.out.printf("%s \t %s \t %s \n", info[i][0], info[i][1], info[i][2]); 
      }else{
        System.out.println("--------------------------");
      }
    }
  }
 
  void ifo(){
    sc = new Scanner(System.in);
  
    System.out.println(count + "번) 사람을 입력하세요.");
    info[count][0] = count + "";
   
    System.out.print("이름을 입력 : ");
    info[count][1] = sc.next();
  
    System.out.print("생일을 입력 : ");
    info[count][2] = sc.next();
  
    count++;
  }
}

 

 

2. RUN

 

 

 

 

// switch ~ case 를 메뉴로 활용한 간단한 예제..