//아래 Source에서 '1.입력'을 통해 들어오는 것들을 '2.출력'에서 모두 다 출력하도록 한다.
/이를 위해서는 Collection을 이용하는 것을 기본으로 한다.
import java.io.*;
public class PersonInfoInput2{
public static void main(String[] args){
String name = null;
int age = 0;
String address = null;
BufferedReader br = null;
try{
br = new BufferedReader(new InputStreamReader(System.in));
while(true){
System.out.println();
System.out.print("1 : 입력 2 : 출력 3 : 종료 ");
String numStr = br.readLine().trim();
if(numStr.equals("1")){
System.out.print("이름을 입력하세요 : ");
name = br.readLine().trim();
if(name.length()==0){
//if(name.equals("")){ }
System.out.println("이름은 한글자 이상 입력하세요");
continue;
}
System.out.print("나이를 입력하세요 : ");
try{
age = Integer.parseInt(br.readLine().trim());
}catch(NumberFormatException ne){
System.out.println("나이는 숫자를 넣으세요");
continue;
}
System.out.print("주소를 입력하세요 : ");
address = br.readLine().trim();
if(address.length()==0){
System.out.println("주소는 한글자 이상 입력하세요");
continue;
}
}else if(numStr.equals("2")){
System.out.println("이름 : "+name+", 나이 : "+age+", 주소 : "+address);
}else if(numStr.equals("3")){
//1. System.exit(0);
//2. break;
//3. return;
return;
}else{
System.err.println("잘못된 값입니다. 1, 2, 3 중 하나를 선택하세요");
continue;
}
}
}catch(IOException ioe){
System.out.println(ioe);
}finally{
if(br!=null){
try{br.close();}catch(IOException ioe){}
}
}
}
}
'Java' 카테고리의 다른 글
File Upload API (0) | 2010.06.13 |
---|---|
Spring에서 자주 사용되어지는 API 묶음 (0) | 2010.06.13 |
간단한 Spring Project 실습하기 (0) | 2010.06.13 |
Spring 설치 및 이클립스와의 연동 (1) | 2010.06.13 |
Tomcat 설치 및 간단한 환경설정 (0) | 2010.04.22 |
PrintWriter Ex. Source (0) | 2010.04.01 |
PrintWriter Ex. Source (0) | 2010.04.01 |
Data In/OutPut StreamTest (0) | 2010.03.31 |
File IO using Buffered IO Stream (0) | 2010.03.31 |
File I/O Ex. Source(2) (0) | 2010.03.31 |