package ints;
public class Arithmetic{
public static int exp(int base, int exponent){
int result = 1;
int i = exponent;
while (i > 0){
result *= base;
i--;
}
return result;
}
public static int fact(int x){
int out = 1;
while (x > 0){
out = out*x;
x--;
}
return out;
}
public static int lcm(int x,int y){
int gcd = gcd(x,y);
return abs(x*y/gcd);
}
public static int lcm2(int x,int y){
if (x < y) { int aux = x; x = y; y = aux; }
int lcm = x;
boolean fin = false;
while (!fin){
if ((lcm%y) == 0)
fin = true;
else
lcm += x;
}
return lcm;
}
public static int gcd(int a,int b){
int res;
while (b != 0){
res = a%b;
a = b;
b = res;
}
return abs(a);
}
public static int factRec(int x){
if (x == 0) return 1;
else return x*factRec(x-1);
}
public static int abs(int x){
if (x >= 0) return x;
else return -x;
}
public static int mod(int x,int y){
if ((x < 0)||(y <= 0)) throw new ArithmeticException();
while (x >= y)
x = x - y;
return x;
}
public static void main(String[] args){
if (args.length > 0)
if (args.length == 1)
abs(Integer.parseInt(args[0]));
else
gcd(Integer.parseInt(args[0]),Integer.parseInt(args[1]));
else
System.out.println("no arguments");
}
}
|