Beautifulkim 2018. 4. 28. 01:46

package study;


public class Index_Study {


public static void main(String[] args) {

//검색기능

//                0  1  2 3 45 6  7  8 <= index

String str = "우리나리 대한민국";

int index = str.indexOf('국');

System.out.printf("'국'의 위치는 : %d\n", index);

index = str.indexOf("대한");

// 떠블커테션 앞에 역슬러쉬 붙이면 문자처리됨

System.out.printf("\" 대한 \"의 위치는 : %d\n", index);

String jumin_no = "901212-1234567";

char gender = jumin_no.charAt(7);

System.out.println(gender);

gender = jumin_no.charAt(0);

System.out.println(gender);

String str_year = jumin_no.substring(0, 0+2);

System.out.println(str_year);

// String -> int변환

int year = Integer.parseInt(str_year);

System.out.println("년도 : " + year);

if(gender=='1' || gender=='2' || gender=='5' || gender=='6')

year = year + 1900;

else

year = year + 2000;


System.out.println("년도는 : " + year);

String str_month = jumin_no.substring(2, 4);

System.out.println("추출한 월 : " + str_month + "월");

String season = "";

/*

3~5 : 봄

6~8 : 여름

9~11 : 가을

12~1,2 : 겨울

*/

//방법1)

//주민번호에 월이 2자리 이기 때문에 2자리로 작성해야 함

switch (str_month) 

{

case "03":

case "04":

case "05": season="봄";break;

case "06":

case "07":

case "08": season="여름";break;

case "09":

case "10":

case "11": season="가을";break;

default: season="겨울";

}

System.out.println("switch 문 : " + season);

//방법2

int month = Integer.parseInt(str_month); //월

switch (month/3) {

case 1: season="봄";break;

case 2: season="여름";break;

case 3: season="가을";break;

default: season="겨울";

}

System.out.println("switch 문: " + month);//12

}


}