package eecs1022.finalb; /** * 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 all ten digits, that is, whether it contains * 0, 1, ..., and 9. You may assume that the string is not null. * * @param s a string. * @return true if the given string contains all ten digits, false otherwise. */ public static boolean containsAll(String s) { boolean containsAll = true; for (char c = '0'; c <= '9'; c++) { boolean found = false; for (int i = 0; i < s.length() && containsAll && !found; i++) { char letter = s.charAt(i); found = letter == c; } containsAll = containsAll && found; } return containsAll; } /** * Tests method. You may add more test cases. * * @param args not applicable. */ public static void main(String[] args) { System.out.println(Question5.containsAll("0123456789")); System.out.println(Question5.containsAll("9876543210")); System.out.println(Question5.containsAll("a9b0c8d1e7f2g6h3i5j4k")); System.out.println(Question5.containsAll("abcdefgh")); System.out.println(Question5.containsAll("123456789")); } }