Skip to content

Instantly share code, notes, and snippets.

@JoeUnsung
Created December 7, 2016 03:20
Show Gist options
  • Save JoeUnsung/88525d4c906274b8dcaba1a978924927 to your computer and use it in GitHub Desktop.
Save JoeUnsung/88525d4c906274b8dcaba1a978924927 to your computer and use it in GitHub Desktop.
Check the number of including specific string in another string.
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