-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumeroPrimo.java
More file actions
47 lines (44 loc) · 1.2 KB
/
numeroPrimo.java
File metadata and controls
47 lines (44 loc) · 1.2 KB
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
import java.util.Scanner;
public class numeroPrimo {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("ingrese un numero");
int numero = scanner.nextInt();
boolean esPrimo = true;
if(numero <= 1){
esPrimo = false;
}
else{
for (int i = 2; i <= 100; i++){
if( numero % i == 0){
esPrimo = false;
break;
}
}
}
if (esPrimo){
System.out.println(numero + "es primo");
}
else{
System.out.println(numero + "no es primo");
}
for (int i = 1; i <= 100; i++){
boolean esPrimoActual = true;
if (i <= 1) {
esPrimoActual = false;
}
else{
for(int j = 2; j <= 100; j++){
if(i % j == 0){
esPrimoActual = false;
break;
}
}
}
if (esPrimoActual) {
System.out.println(i);
}
}
scanner.close();
}
}