forked from miafg/fun-with-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDumbString.java
38 lines (35 loc) · 831 Bytes
/
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
/**
* This class contains some dumb methods for use with Strings.
* Hence the name.
* @author chris
*
*/
public class DumbString {
/**
* @param s String to check
* @return true if all chars in s are digits ('0'-'9') and false otherwise
*/
public 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;
}
}