-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsValidHex.java
More file actions
15 lines (15 loc) · 908 Bytes
/
IsValidHex.java
File metadata and controls
15 lines (15 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class IsValidHex {
public static boolean isValidHexMethod(String hex) {
if (hex.length() != 7) return false;
if (hex.charAt(0)!='#') return false;
for (int i = 1; i<hex.length(); i++) {
if (hex.charAt(i) != 'A' && hex.charAt(i) != 'B' && hex.charAt(i) != 'C' && hex.charAt(i) != 'D' && hex.charAt(i) != 'E' && hex.charAt(i) != 'F' &&
hex.charAt(i) != 'a' && hex.charAt(i) != 'b' && hex.charAt(i) != 'c' && hex.charAt(i) != 'd' && hex.charAt(i) != 'e' && hex.charAt(i) != 'f' &&
hex.charAt(i) != '0' && hex.charAt(i) != '1' && hex.charAt(i) != '2' && hex.charAt(i) != '3' && hex.charAt(i) != '4' && hex.charAt(i) != '5' &&
hex.charAt(i) != '6' && hex.charAt(i) != '7' && hex.charAt(i) != '8' && hex.charAt(i) != '9') {
return false;
}
}
return true;
}
}