Skip to content

Commit a4788c1

Browse files
committed
feat: Add regex-based check to determine if a number is binary
- Converts an integer value (e.g., 1000110) into a String using `String.valueOf()`. - Uses `String.matches("[01]*")` to validate whether the number contains only binary digits (0s and 1s). - The regular expression `[01]*` ensures the string contains **zero or more** characters that are either '0' or '1'. - Prints `true` if the input is a valid binary number; otherwise, prints `false`. Example: Input: 1000110 Output: true (since all digits are either 0 or 1) This implementation leverages Java’s regex API for a concise binary number validation approach. Signed-off-by: Somesh diwan <[email protected]>
1 parent 2ae5d42 commit a4788c1

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

Section6StringClassPrinting/src/RegularExpressionChallenge.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//Find number binary or not.
2+
13
public class RegularExpressionChallenge {
24
public static void main(String[] args) {
35
int b = 1000110;

0 commit comments

Comments
 (0)