방치하기

주민 번호님 인수로 받아서 남녀 구별해주기 .substring 본문

홍익대 Java/과제

주민 번호님 인수로 받아서 남녀 구별해주기 .substring

Yi Junho 2009. 7. 16. 19:51
반응형
1
2
3
class w2{ <br>
     public static void main(String[] args) <br>
    {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
        String str = args[0];<br>
        char ch;<br>
        ch=str.charAt(6);<br>
    int a=(int)ch;<br>
        <br>
    if (48<a && a<58)<br>
        {<br>
     if(ch=='1'||ch=='3')<br>
        System.out.printf("남자입니다.",ch);<br>
      else<br>
       System.out.printf("여자입니다.",ch);<br>
        }<br>
    else if(ch=='-')<br>
    {<br>
     ch=str.charAt(7);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
     if(ch=='1'||ch=='3')<br>
        System.out.printf("남자입니다.",ch);<br>
     else<br>
      System.out.printf("여자입니다.",ch);<br>
    }<br>
    else <br>
    {<br>
     System.out.printf("주민번호를 입력하란말이야 ㅠ");<br>
    }<br>
        //생년월일 출력<br>
    System.out.println();<br>
        int birth= Integer.parseInt("19"+str.substring(0,2)); <br>
    int month = Integer.parseInt(str.substring(2,4)); <br>
    int day =Integer.parseInt(str.substring(4,6));<br>
    System.out.println("당신의 생년월일은"+birth+"년"+month+"월"+day+"일 입니다");<br>
     } <br>
}
반응형
Comments