uaveiro-leci/1ano/2semestre/poo/src/utils/MathTools.java

24 lines
585 B
Java
Raw Normal View History

2023-02-18 14:09:52 +00:00
package utils;
import java.util.Random;
2023-02-18 14:09:52 +00:00
public class MathTools {
public static double round(double n, int places) {
return (Math.round(n * Math.pow(10, places))) / Math.pow(10, places);
}
public static double random(double minLimit, double maxLimit) {
Random rand = new Random();
return rand.nextDouble(minLimit, maxLimit);
}
public static boolean isNumPrime(int n) {
if (n <= 1)
return false;
for (int i = 2; i < n; i++)
if (n % i == 0)
return false;
return true;
}
2023-02-18 14:09:52 +00:00
}