class MathMethods{
//METODOS SIMPLES
public double Suma(double num1, double num2){
return num1+num2;
}
public double Resta(double num1,double num2){
return num1-num2;
}
public double Multiplicacion(double num1, double num2){
return num1*num2;
}
public double Cociente(double num1,double num2){
if(num2 != 0){
return num1/num2;
}
}
public double Resto(double num1,double num2){
if(num2!=0){
return num1%num2;
}
}
public String Division(double num1, num2){
if(num2 !=0){
return num1+"/"+num2+"="+num1/num2+". COCIENTE="+num1%num2
}
}
//METODOS COMPLEJOS
public double Exponente(double num1, double num2){
return num1**num2;
}
public int Factorial(int num1){
int factorial=1;
while(num1 >0){
factorial+=num1*(num1-1);
num1--;
}
return factorial;
}
public String Factorizar(int num1){
String factor="{ ";
for(int inicio=1; inicio < num1;inicio++){
if(num1%inicio==0){
factor+=inicio+", ";
}
}
return factor+num1.toString()+"}";
}
public int Menor(int n1, int n2){
if(n1>n2){
return n1;
}else{
return n2;
}
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.