Skip to content

Commit 0551e82

Browse files
committed
feat: Add regex-based check to validate hexadecimal number format
- Implements a simple Java program to check if a given string is a valid hexadecimal number. - Uses the regular expression `[0-9A-F]*` to match any string composed solely of hexadecimal characters. - `[0-9A-F]` matches any digit (0–9) or uppercase letter A–F (representing values 10–15). - `*` quantifier allows zero or more such characters (use `+` to require at least one). - Example used: "234AB" — a valid hexadecimal number, so the output is `true`. 📝 Notes: - This validation assumes uppercase hex letters. To handle lowercase or mixed case, use `[0-9A-Fa-f]*`. - Hexadecimal numbers are widely used in computing, often for memory addresses, color codes, etc. Signed-off-by: Somesh diwan <[email protected]>
1 parent a4788c1 commit 0551e82

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
//Find is number is hexa decimal or not
22
//[0-9A-F]+ plus is they are one or more
33

4-
public class RegularExpressionChallenge1
5-
{
6-
public static void main(String[] args)
7-
{
4+
public class RegularExpressionChallenge1 {
5+
public static void main(String[] args) {
86
String str = "234AB";
97
System.out.println(str.matches("[0-9A-F]*"));
10-
11-
//The hexadecimal number system, often referred to as "hex," is a base-16 numeral system used extensively in computing and digital electronics.
12-
//It consists of 16 symbols: the numbers 0 to 9 and the letters A to F. These letters represent the decimal values 10 to 15, respectively
8+
/*
9+
The hexadecimal number system, often referred to as "hex," is a base-16 numeral system used extensively in
10+
computing and digital electronics.
11+
It consists of 16 symbols: the numbers 0 to 9 and the letters A to F.
12+
These letters represent the decimal values 10 to 15, respectively
13+
*/
1314
}
14-
}
15+
}

0 commit comments

Comments
 (0)