Utilizando una función propia de módulo.
Código (java) [Seleccionar]
/*
* Autor: Darhius929
*/
package basic;
public class Dividers {
private static final int LOWER_LIMIT = 1;
private static final int SUPERIOR_LIMIT = 15000;
public static void main(String args[]) {
int divisor3 = 3;
numbersDivisible(divisor3);
int divisor5 = 5;
numbersDivisible(divisor5);
int divisor7 = 7;
numbersDivisible(divisor7);
}
private static void numbersDivisible(int divisor) {
for(int number=LOWER_LIMIT; number<SUPERIOR_LIMIT; number++){
if(module(number,divisor)==0) {
System.out.println("El n\u00famero " + number + " es divisor de " + divisor);
}
}
}
private static double module(double dividend, double divisor) {
double remainder = 0.0;
try {
remainder = dividend - ((int)(dividend/divisor)*divisor);
} catch(ArithmeticException ae) {
ae.printStackTrace();
}
return remainder;
}
}