-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringE
More file actions
26 lines (26 loc) · 784 Bytes
/
stringE
File metadata and controls
26 lines (26 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*Return true if the given string contains between 1 and 3 'e' chars.
stringE("Hello") → true
stringE("Heelle") → true
stringE("Heelele") → false
*/
public class stringE {
public static void main(String[] args) {
boolean output=stringE("Hello");
System.out.println(output);
boolean output1=stringE("Heelle");
System.out.println(output1);
boolean output2=stringE("Heelele");
System.out.println(output2);
}
public static boolean stringE(String str) {
int count = 0;
for (int i = 0; i<str.length(); i++){
if (str.substring(i,i+1).equals("e"))
count++;
}
if ((count >= 1) && (count <= 3))
return true;
else
return false;
}
}