Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 08cae95

Browse files
Kyu 8 | All Star Code Challenge #18
1 parent 7b9b3b2 commit 08cae95

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

‎src/main/java/kyu8/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Kata Found realized
2222

2323
- [Age Range Compatibility Equation](ageRangeCompatibilityEquation)
2424

25+
- [All Star Code Challenge #18](allStarCodeChallenge18)
26+
2527
- [Find Nearest square number](findNearestSquareNumber)
2628

2729

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package kyu8.allStarCodeChallenge18;
2+
3+
public class CodeWars {
4+
public static int strCount(String str, char letter) {
5+
int result = 0;
6+
for (int i = 0; i < str.length(); i++) {
7+
if (str.charAt(i) == letter) {
8+
result++;
9+
}
10+
}
11+
return result;
12+
}
13+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# All Star Code Challenge #18
2+
3+
Create a function that accepts a string and a single character, and returns an integer of the count of occurrences the 2nd argument is found in the first one.
4+
5+
If no occurrences can be found, a count of 0 should be returned.
6+
7+
Example (**Inputs** --> **Output**)
8+
9+
```java
10+
("Hello", "o") ==> 1
11+
("Hello", "l") ==> 2
12+
("", "z") ==> 0
13+
```
14+
15+
```java
16+
str_count("Hello", 'o'); // returns 1
17+
str_count("Hello", 'l'); // returns 2
18+
str_count("", 'z'); // returns 0
19+
```
20+
21+
Notes:
22+
23+
- The first argument can be an empty string
24+
25+
- The second string argument will always be of length 1
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package kyu8.allStarCodeChallenge18;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
public class testCodeWars {
8+
@Test
9+
public void testSomething() {
10+
assertEquals(1, CodeWars.strCount("Hello", 'o'));
11+
assertEquals(2, CodeWars.strCount("Hello", 'l'));
12+
assertEquals(0, CodeWars.strCount("", 'z'));
13+
}
14+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /