forked from ChrisMurphyOnline/github-issues-activity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDumbString.java
59 lines (54 loc) · 1.21 KB
/
DumbString.java
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* This class contains some dumb methods for use with Strings.
* Hence the name.
* @author chris
*
*/
public class DumbString {
/**
*static
* @param s String to check
* @return true if all chars in s are digits ('0'-'9') and false otherwise
*/
public static boolean allDigits(String s) {
for (char c : s.toCharArray()) {
if (Character.isDigit(c) == false)
return false;
}
return true;
}
/**
* Determines the number of letters that the two parameters have in common
* @param a
* @param b
* @return the number of letters the two Strings have in common; -1 if either is null
*/
public static int lettersInCommon(String a, String b) {
if (a == null && b == null) {
return -1;
}
int common = 0;
for (char c : a.toCharArray()) {
if (b.indexOf(c) != -1) {
common++;
}
}
return common;
}
public static boolean noDigits(String input) {
for (char c: input.toCharArray()) {
if (0 < c) {
return true;
} else {
return false;
}
}
/**
* Determines if the string passed contains at least one digit
* @param a
* @return true if a contains digits
*/
public static boolean hasDigit(String a) {
return a.matches(".*\\d+.*");
}
}