public class CountChars {

  // countChars : Takes a String s and a char c, and evaluates to
  // the number of times c appears in s (as an int).
  public static int countCharsA(String s, char c) {
    int total = 0, index = 0;
    while(index < s.length()) {
      if(s.charAt(index) == c) { total += 1; }
      index += 1;
    }
    return total;
  }

  public static int countChars(String s, char c) {
    int total = 0;
    for(int index = 0; index < s.length(); index += 1) {
      if(s.charAt(index) == c) { total += 1; }
    }
    return total;
  }

  public static void main(String[] args) {

    String s = "It's a sunny day!";
    //          ^^^^            ^
    //          0123...        16

    System.out.println(s.charAt(3)); // prints s

    System.out.println(countChars("It's a sunny day!", 'y')); // 2
    System.out.println(countChars("It's a sunny day!", 'u')); // 1
    System.out.println(countChars("It's a sunny day!", 'x')); // 0

  }

}























/*
  public static int countChars(String s, char c) {
    int total = 0, index = 0;
    while(index <= s.length()) {
      if(s.charAt(index) == c) { total += 1; }
      index += 1;
    }
    return total;
  }
  public static int countChars(String s, char c) {
    int total = 0, index = 0;
    while(index < s.length()) {
      if(s.charAt(index) == c) { total += 1; }
      index += 1;
    }
    return total;
  }
  public static int countChars(String s, char c) {
    int total = 0;
    for(int index = 0; index < s.length(); index += 1) {
      if(s.charAt(index) == c) { total += 1; }
    }
    return total;
  }
  public static int countChars(String s, char c) {
    int total = 0, index = 0;
    while(index < s.length()) {
      if(s.charAt(index) == c) {
        total += 1;
        index += 1;
      }
    }
    return total;
  }
*/
