-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotString
More file actions
23 lines (21 loc) · 812 Bytes
/
notString
File metadata and controls
23 lines (21 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//Given a string, return a new string where "not " has been added to the front. However, if the string already begins
// with "not", return the string unchanged. Note: use .equals() to compare 2 strings.
//notString("candy") → "not candy"
//notString("x") → "not x"
//notString("not bad") → "not bad"
public class notString {
public static void main(String[] args) {
String output = notString("candy");
System.out.println(output);
String output1=notString("x");
System.out.println(output1);
String output2=notString("not bad");
System.out.println(output2);
}
public static String notString(String a) {
if (a.length() >= 3 && a.substring(0, 3).equals("not")) {
return a;
} else
return "not " + a;
}
}