여기 여기 내 솔루션그래서 내가 궁금
public int count_chars_in_String(String s, String s1){
int count = 0;
for(int j = 0; j<s1.length(); j++){
for(int i = 0; i<s.length();i++){
if(s.charAt(i) == s1.charAt(j)){
count += 1;
}
}
}
하고하는 것은 때마다 내가 JUnit 테스트를 실행 내 나머지 코드
@Test public void tests4(){
code.Solution s = new code.Solution();
String input = "hhhhhey ";
String input1 = "hhh";
int expected = 3;
int actual = s.count_chars_in_String(input, input1);
assertTrue("Expected was" +expected+"but the actual was" +actual , expected == actual);
}
입니다 예상치는 3 이었지만 실제 수치는 15였습니다. 어떻게 나는 혼란 스럽다. 당신이 3 아마 같을 것이다 결과를 줄 것이다
두 문자열에서 동일한 위치 또는 다른 문자열에서 일치하는 항목을 찾으려고합니까? – rgettman
두 문자열에서 동일한 대응 문자를 matche하려고합니다. 해당 위치가 – QifengSun