질문)
이름과 생일을 입력받아서 각각 변수에 저장한뒤
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 를 메뉴로 활용한 간단한 예제..
'course > 지식인' 카테고리의 다른 글
[자바] switch ~ case을 메뉴로 사용해서 입/출력 기능 추가. (3) | 2016.06.16 |
---|---|
[자바] switch ~ case을 값을 수정할 때 사용해서 배열값을 변경. (0) | 2016.06.15 |
[자바] 평균과 분산 구하기 (0) | 2016.06.14 |