Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface MyCustomStringInterface {
- int countNumbers();
- }
- public class MyCustomString implements MyCustomStringInterface {
- private String string;
- @Override
- public int countNumbers() {
- while (string.length() != 0 ) {
- int count = 0;
- for (int i = 0; i < string.length(); i++) {
- if(Character.isDigit(string.charAt(i))) count++;
- }
- return count;
- }
- return 0;
- }
- public class MyCustomStringTest {
- private MyCustomStringInterface mycustomstring;
- @Test
- public void testCountNumbers1() {
- mycustomstring.setString("th1s strin8 shou1d hav3 numb3rs,
- righ7?");
- assertEquals(6, mycustomstring.countNumbers());
- }
- }
Add Comment
Please, Sign In to add comment