-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumber.java
More file actions
127 lines (115 loc) · 2.91 KB
/
Number.java
File metadata and controls
127 lines (115 loc) · 2.91 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
public class Number {
private int a;
Number(int a) {
this.a = a;
}
public boolean isZero(int b) {
if (b == 0) {
return true;
} else {
return false;
}
}
public boolean isPositive(int b) {
if (b > 0) {
return true;
} else {
return false;
}
}
public boolean isNegative(int b) {
if (b < 0) {
return true;
} else {
return false;
}
}
public boolean isOdd(int b) {
if (b % 2 != 0) {
return true;
} else {
return false;
}
}
public boolean isEven(int b) {
if (b % 2 == 0) {
return true;
} else {
return false;
}
}
public boolean isPrime(int b) {
int c = 0;
for (int i = 2; i < b; i++) {
if (b % i == 0) {
c = c + 1;
}
}
if (c == 0) {
return true;
} else {
return false;
}
}
public boolean isArmstrong(int b) {
int d = b;
int e;
int f = 0;
while (b >= 1) {
e = b % 10;
b = b / 10;
f += e * e * e;
}
if (f == d) {
return true;
} else {
return false;
}
}
public int getFactorial(int b) {
int d = 1;
int e = 0;
for (int i = 1; i <= b; i++) {
for (int j = 1; j <= i; j++) {
d *= j;
}
e += d;
}
return e;
}
public int getSqrt(int b) {
return (int) Math.sqrt(b);
}
public int gerSqr(int b){
return b*b;
}
public int sumDigits(int a, int b, int c){
return a+b+c;
}
public String dispBinary(int b){
return Integer.toBinaryString(b);
}
public String dispOctal(int b){
return Integer.toOctalString(b);
}
public String dispHexa(int b){
return Integer.toHexString(b);
}
public static void main(String[] args) {
Number obj = new Number(213);
System.out.println(obj.dispBinary(2));
System.out.println(obj.dispHexa(obj.a));
System.out.println(obj.dispOctal(obj.a));
System.out.println(obj.gerSqr(4));
System.out.println(obj.getFactorial(5));
System.out.println(obj.getSqrt(25));
System.out.println(obj.isArmstrong(370));
System.out.println(obj.isEven(obj.a));
System.out.println(obj.isNegative(-2));
System.out.println(obj.isOdd(1));
System.out.println(obj.isPositive(4));
System.out.println(obj.isPrime(5));
System.out.println(obj.isZero(0));
System.out.println(obj.sumDigits(3, 4, 3));
}
}