-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHAS_BAD.java
More file actions
32 lines (27 loc) · 742 Bytes
/
HAS_BAD.java
File metadata and controls
32 lines (27 loc) · 742 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
27
28
29
30
31
32
/*
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 school;
public class HAS_BAD {
public static void main(String[] args){
boolean answer = hasBad("badxx");
System.out.println(answer);
}
public static boolean hasBad(String str) {
if(str.length()<=3){
if(str.equals("bad"))
{ return true;}
return false;
}else
{
if(str.substring(0,3).equals("bad") || str.substring(1,4).equals("bad") ){
return true;
}
}return false;
}
}