forked from achabill/mathemataica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mathematica.java
37 lines (37 loc) · 908 Bytes
/
Mathematica.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
import java.util.ArrayList;
public class Mathematica{
public static int sum(int a, int b){
return a + b;
}
public static int power(int a, int b) {
int result = a;
for (int i = 1; i <= b; i++){
result *= a;
}
return result;
}
public static int subtract(int a, int b) {
return a - b;
}
public static int multiply(int a, int b){
return a * b;
}
public static int divide(int a, int b){
return a / b;
}
public static int abs(int x){
if (x > 0)
return x;
else
return x * -1;
}
public static ArrayList<Integer> getfactors(int x){
ArrayList<Integer> factors = new ArrayList<Integer>();
for (int i = 1; i <= x; i++){
if (x % i == 0){
factors.add(i);
}
}
return factors;
}
}