Created
December 7, 2016 03:20
-
-
Save JoeUnsung/88525d4c906274b8dcaba1a978924927 to your computer and use it in GitHub Desktop.
Check the number of including specific string in another string.
This file contains hidden or 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 joe; | |
import java.lang.*; | |
import java.util.*; | |
import java.io.*; | |
public class HW3_PRAC { | |
public static int count(String src, String target){ | |
char temp1, temp2; | |
int cnt = 0; | |
temp1 = target.charAt(0); | |
temp2 = target.charAt(1); | |
for(int i = 0 ; i < src.length() ; i++){ | |
if(temp1 == src.charAt(i)){ | |
if(temp2 == src.charAt(i+1)){ | |
cnt++; | |
} | |
} | |
} | |
return cnt; | |
} | |
public static void main(String[] args){ | |
System.out.println(count("12345AB12AB345AB", "AB")); | |
System.out.println(count("12345", "AB")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment