-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpers.java
More file actions
62 lines (58 loc) · 952 Bytes
/
Helpers.java
File metadata and controls
62 lines (58 loc) · 952 Bytes
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
public class Helpers
{
static boolean isInteger(String str)
{
try
{
int d = Integer.parseInt(str);
}
catch(NumberFormatException nfe)
{
return false;
}
return true;
}
static int extractUnsignedInt(String input)
{
try
{
int num = Integer.parseUnsignedInt(input);
return num;
}
catch (NumberFormatException e)
{
System.err.println("Invalid input");
return -1;
}
}
static int extractUnsignedInt(String input, int maxValue)
{
try
{
int num = Integer.parseUnsignedInt(input);
if (num <= maxValue)
return num;
return -1;
}
catch (NumberFormatException e)
{
System.err.println("Invalid input");
return -1;
}
}
static int extractInt(String input, int maxValue)
{
try
{
int num = Integer.parseInt(input);
if (num <= maxValue)
return num;
return -1;
}
catch (NumberFormatException e)
{
System.err.println("Invalid input");
return -1;
}
}
}