forked from riya2001-cloud/java-hacktober
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumber.java
50 lines (48 loc) · 817 Bytes
/
Number.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
47
48
49
50
public class Number
{
private int num;
public Number(int num)
{
this.num = num;
}
public boolean isPositive()
{
return num >= 0;
}
public boolean isEven()
{
return num % 2 == 0;
}
public boolean isPrime()
{
// Corner case
if (n <= 1)
{
return false;
}
// Check from 2 to n-1
for (int i = 2; i < n; i++)
{
if (n % i == 0)
{
return false;
}
}
return true;
}
public void setNum(int num)
{
try
{
this.num = num;
}
catch(Exception e)
{
e.printStackTrace();
}
}
public int getNum()
{
return num;
}
}