Java/Java Training
11-1-2
군우
2018. 1. 19. 21:46
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | package overlaod; public class overload1102 { public static void main(String[] args) { StringBuilder str = new StringBuilder("990220-101210"); System.out.println(str); System.out.println(str.replace(1,3,"123")); // deleteCharAt(인데스번호) 메소드는 주소번호에 해당하는 것을지움. int a=0; if(str.lastIndexOf("-") != -1){ // lastIndexOf 문자찾는거 a = str.lastIndexOf("-"); } //System.out.println(a); System.out.println("답"+str.deleteCharAt(a)); System.out.println(str.reverse()); } } | cs |
답
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | package overlaod; public class overload1102t { public static void main(String[] args) { String str = "999909-999999"; StringBuilder sbuf = new StringBuilder(str); int idx = sbuf.lastIndexOf("-"); if(idx != -1){ sbuf.deleteCharAt(idx); } str = sbuf.toString(); System.out.println(str); } } | cs |
14번째 줄을 제거하면 원래 str이 나온다 . toStirng() 의 사용법을 알아야겟다.