카테고리 없음

오늘의 유머 - 프로그래머 게시판 6918 번

루트노드 2014. 12. 4. 11:28

프게글

풀이


  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. public class Main {
  5. public static void main(String[] args){
  6. String str = "국가 (0,2)(1,1)(2,1)(6,1)(8,1)(12,1)";
  7. Pattern p = Pattern.compile("\\((\\d+),(\\d+)\\)");
  8. Matcher m = p.matcher(str);
  9. System.out.println("괄호 포함, 괄호 안 전체");
  10. while (m.find()){
  11. System.out.println(m.group());
  12. }
  13. m.reset();
  14. System.out.println("괄호 안, 콤마 왼쪽");
  15. while (m.find()){
  16. System.out.println(m.group(1));
  17. }
  18. m.reset();
  19. System.out.println("괄호 안, 콤마 오른쪽");
  20. while (m.find()){
  21. System.out.println(m.group(2));
  22. }
  23. }
  24. }
  25.