-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEVA1_23_NUMEROS_PRIMOS.java
48 lines (40 loc) · 1.39 KB
/
EVA1_23_NUMEROS_PRIMOS.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package eva1_23_numeros_primos;
import java.util.Scanner;
/**
*
* @author mague
*/
public class EVA1_23_NUMEROS_PRIMOS {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here7
Scanner input = new Scanner(System.in);
int ival = input.nextInt();
boolean esPrimo = true;
for (int i = 0; i< ival; i++){ //MENOR --> NUNCA DEBE SER IGUAL O MAYOR
//Division iVal/i
//MODULO -->CALCULA EL RESIDUO DE LA DIVISION
//EL MODULO EN JAVA ES % --> NUM1 % NUM2%
//7 % 5 = 2
int iMod = ival % i;
if (iMod ==0){//El modulo es igual a 0, no es primo, hay que terminar
esPrimo = false;
}
//continue; //Detiene la iteracion actual
// break; //Detiene permanentemente el for
//Si la division es exacta --> terminamos y no es primo
//Si terminamos el for sin dividir exactamente es primo
}
if (esPrimo)
System.out.println("El numero es Primo");
else
System.out.println("EL numero no es Primo");
}
}