package test5; import java.util.List; public class Test5F { /** * Returns the number of a's in the given string. * * @param word a string * @pre. word != null * @return the number of a's in the given string. */ public static int numberOfAs(String word) { int number; if (word.length() == 0) { number = 0; } else { number = word.charAt(0) == 'a' ? 1 : 0; number += Test5F.numberOfAs(word.substring(1)); } return number; } /** * Tests whether all strings of the given list have the same * length. * * @param sentence a list of strings * @pre. sentence != null * @return true if all strings of the given list have the same * length, false otherwise. */ public static boolean sameLength(List sentence) { boolean same; if (sentence.size() <= 1) { same = true; } else { same = sentence.get(0).length() == sentence.get(1).length() && Test5F.sameLength(sentence.subList(1, sentence.size())); } return same; } }