-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhasBad
More file actions
24 lines (23 loc) · 835 Bytes
/
hasBad
File metadata and controls
24 lines (23 loc) · 835 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
/*Given a string, return true if "bad" appears starting at index 0 or 1 in the string, such as with "badxxx" or
"xbadxx" but not "xxbadxx". The string may be any length, including 0. Note: use .equals() to compare 2 strings.
hasBad("badxx") → true
hasBad("xbadxx") → true
hasBad("xxbadxx") → false
*/
package string1;
public class hasBad {
public static void main(String[] args) {
boolean output=hasBad("badxx");
System.out.println(output);
boolean output1=hasBad("xbadxx");
System.out.println(output1);
boolean output2=hasBad("xxbadxx");
System.out.println(output2);
}
public static boolean hasBad(String str) {
if (str.substring(0,3).equals("bad") || str.substring(1,4).equals("bad"))
return true;
else
return false;
}
}