stringE

Return true if the given string contains between 1 and 3 ‘e’ chars.

stringE(“Hello”) ? true
stringE(“Heelle”) ? true
stringE(“Heelele”) ? false

public boolean stringE(String str) {
int n=0;
char str1[]=str.toCharArray();
for(int i=0;i<str1.length;i++)
if(str1[i]=='e') n++;

if(n==1 || n==3) return true;
else return false;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s