Guest User

Untitled

a guest
Feb 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. public interface MyCustomStringInterface {
  2. int countNumbers();
  3. }
  4.  
  5. public class MyCustomString implements MyCustomStringInterface {
  6. private String string;
  7.  
  8.  
  9.  
  10. @Override
  11. public int countNumbers() {
  12. while (string.length() != 0 ) {
  13. int count = 0;
  14. for (int i = 0; i < string.length(); i++) {
  15. if(Character.isDigit(string.charAt(i))) count++;
  16. }
  17. return count;
  18. }
  19. return 0;
  20. }
  21.  
  22. public class MyCustomStringTest {
  23. private MyCustomStringInterface mycustomstring;
  24.  
  25. @Test
  26. public void testCountNumbers1() {
  27. mycustomstring.setString("th1s strin8 shou1d hav3 numb3rs,
  28. righ7?");
  29.  
  30. assertEquals(6, mycustomstring.countNumbers());
  31. }
  32. }
Add Comment
Please, Sign In to add comment