Skip to content

Instantly share code, notes, and snippets.

@morishjs
Created July 19, 2016 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morishjs/86dcd339aa8b350b2118e245bdcf9070 to your computer and use it in GitHub Desktop.
Save morishjs/86dcd339aa8b350b2118e245bdcf9070 to your computer and use it in GitHub Desktop.
Simple pattern matcher with Pattern class
package Java0719_api;
/*
* sn변수에 저장된 문자열중에서 숫자갯수를 출력하는 프로그램을 구현하시오.
* [출력결과]
* 숫자갯수:3
*/
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Java140_Wrapper {
public static void main(String[] args) {
String sn="korea12 paran3";
Pattern p = Pattern.compile("[0-9]");
Matcher m = p.matcher(sn);
int count = 0;
while (m.find()) {
count++;
}
System.out.println(count);
}// end main()
}// end class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment