Created
July 19, 2016 04:36
-
-
Save morishjs/86dcd339aa8b350b2118e245bdcf9070 to your computer and use it in GitHub Desktop.
Simple pattern matcher with Pattern class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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