susillo guapillo
unknown
java
4 years ago
1.5 kB
10
Indexable
/*
* diseñar una funcion que recibe como parametros
* dos numeros enteros y muestre todos los numeros primos entre ellos
*/
package primos;
import java.util.*;
/**
*
* @author TEST
*/
public class Primos {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
sc.useLocale(Locale.US);
int first, second;
int a; //numero menor
int b; //numero mayor
int it;//iteracion de comrpobacion de primos
System.out.println("Indique dos números para mostrar los primos entre ambos:");
System.out.println("Indique el menor de los dos números:");
first = sc.nextInt();
System.out.println("Indique el mayor de los dos números:");
second = sc.nextInt();
if (first < second){
a = first;
b = second;
}
else {
a = second;
b = first;
}
it = a;
while (it <= b){
if (esPrimo(it)){
System.out.println(it);
}
it++;
}
}
public static boolean esPrimo(int n){
int div; //divisor
if (n<=1){
return false;
}
div = 2;
while (div <= Math.sqrt(n)){
if (n % div == 0){
return false;
}
div++;
}
return true;
}
}
Editor is loading...