Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are given a String variable aStr that contains a String. Write a segment of

ID: 3631089 • Letter: Y

Question

You are given a String variable aStr that contains a String.
Write a segment of Java code that will count the number of times a lowercase letter 'e' appears in aStr, and will print out the answer in exactly the form shown below. For example, if aStr contained the String "elementary" then your program would print
No. of little e's = 3
because aStr contained three occurrences of the letter 'e'.
Note: This is only an example. Your code must be general and must work correctly for any String aStr.

String aStr = scan.next();

Explanation / Answer

int countes(String aStr)

{

int count=0;

for(int i=0; i<aStr.lenth(); i++)

{

if(aStr.charAt(i) == 'e')

count++;

}

return count;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote