package eecs1022.finalc; /** * This question is worth 2.5 marks. No partial marks will be awarded for this question. * * @author Franck van Breugel */ public class Question5 { /** * Tests whether the given string contains at least five digits. * You may assume that the string is not null. * * @param s a string. * @return true if the given string contains at least five digits, false otherwise. */ public static boolean containsAtLeastFive(String s) { final int LIMIT = 5; int count = 0;; for (char c = '0'; c <= '9'; c++) { boolean found = false; for (int i = 0; i < s.length() && !found; i++) { char letter = s.charAt(i); found = letter == c; } if (found) { count++; } } return count >= LIMIT; } /** * Tests method. You may add more test cases. * * @param args not applicable. */ public static void main(String[] args) { System.out.println(Question5.containsAtLeastFive("1234")); System.out.println(Question5.containsAtLeastFive("54830")); System.out.println(Question5.containsAtLeastFive("a1b2c3d4e5f")); System.out.println(Question5.containsAtLeastFive("abcdefgh")); System.out.println(Question5.containsAtLeastFive("8defhg7fhketd4")); } }