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
}
}
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)