2. Write the method named countChar() * * You are given a String str, and a char ch. * Return the number of times that ch appears * inside str, but ignore case. * * Oh, and you can't use the classification methods * in the Character class. Use plain if statements, * remembering that you can check if ch is lowercase * by checking if it is between lowercase 'a' and * lowercase 'z', inclusive. Likewise, check if * between 'A' and 'Z' for capital. To convert lowercase to * uppercase, subtract the difference between lowercase 'a' * and uppercase 'A' ('a'-'A') from the lowercase character. * Add this difference to convert from uppercase to lowercase. * * Examples: * countChar("Abcdefg", 'a') returns 1 * countChar("xxXx", 'x') returns 4 * countChar("", 'q') returns 0 * * @param str the String to search through * @param ch the char to count (not case sensitive) * @return the count of ch in str */ public int countChar(String str, char ch) { // Complete the countChar method here } }
2. Write the method named countChar()
*
* You are given a String str, and a char ch.
* Return the number of times that ch appears
* inside str, but ignore case.
*
* Oh, and you can't use the classification methods
* in the Character class. Use plain if statements,
* remembering that you can check if ch is lowercase
* by checking if it is between lowercase 'a' and
* lowercase 'z', inclusive. Likewise, check if
* between 'A' and 'Z' for capital. To convert lowercase to
* uppercase, subtract the difference between lowercase 'a'
* and uppercase 'A' ('a'-'A') from the lowercase character.
* Add this difference to convert from uppercase to lowercase.
*
* Examples:
* countChar("Abcdefg", 'a') returns 1
* countChar("xxXx", 'x') returns 4
* countChar("", 'q') returns 0
*
* @param str the String to search through
* @param ch the char to count (not case sensitive)
* @return the count of ch in str
*/
public int countChar(String str, char ch)
{
// Complete the countChar method here
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images