public class CountA { public static int count_a(String str) { // Verwenden Sie dafür nur eine for-Schleife und eine if-Abfrage // Sie dürfen die Methoden length() und charAt(int i) der Klasse String verwenden int i = 0; for (int j = 0; j < str.length(); j++) { if ( str.charAt(j) == 'a' ) { i++; } else { } } return i; } public static void main(String[] args) { assert (count_a("") == 0); assert (count_a("a") == 1); assert (count_a("aa") == 2); assert (count_a("abb ") == 1); assert (count_a(" abba ") == 2); assert (count_a("bb") == 0); System.out.println(" Everything good !"); } }