홍익대 Java/과제
주민 번호님 인수로 받아서 남녀 구별해주기 .substring
Yi Junho
2009. 7. 16. 19:51
반응형
class w2{
public static void main(String[] args)
{
String str = args[0];
char ch;
ch=str.charAt(6);
int a=(int)ch;
if (48<a && a<58)
{
if(ch=='1'||ch=='3')
System.out.printf("남자입니다.",ch);
else
System.out.printf("여자입니다.",ch);
}
else if(ch=='-')
{
ch=str.charAt(7);
if(ch=='1'||ch=='3')
System.out.printf("남자입니다.",ch);
else
System.out.printf("여자입니다.",ch);
}
else
{
System.out.printf("주민번호를 입력하란말이야 ㅠ");
}
//생년월일 출력
System.out.println();
int birth= Integer.parseInt("19"+str.substring(0,2));
int month = Integer.parseInt(str.substring(2,4));
int day =Integer.parseInt(str.substring(4,6));
System.out.println("당신의 생년월일은"+birth+"년"+month+"월"+day+"일 입니다");
}
}
반응형