-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOctalNumber.java
46 lines (41 loc) · 978 Bytes
/
OctalNumber.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
package com.javamultiplex.number;
import java.util.Scanner;
/**
*
* @author Rohit Agarwal
* @problem Number is octal or not
*
*/
public class OctalNumber {
public static void main(String[] args) {
Scanner input = null;
try {
input = new Scanner(System.in);
System.out.println("Enter number : ");
String number = input.next();
/*
* Regular expression that matches string containing only
* digits[0-9].
*/
String pattern1 = "^[0-9]+$";
if (number.matches(pattern1)) {
/*
* Regular expression that matches string containing only octal
* digits[0-7].
*/
String pattern2 = "^[0-7]+$";
if (number.matches(pattern2)) {
System.out.println("It is octal.");
} else {
System.out.println("It is not octal.");
}
} else {
System.out.println("Please enter valid number.");
}
} finally {
if (input != null) {
input.close();
}
}
}
}