-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodigo6.java
More file actions
33 lines (22 loc) · 832 Bytes
/
codigo6.java
File metadata and controls
33 lines (22 loc) · 832 Bytes
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
package org.codigo6;
public class codigo6 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] n = new int[20]; // colocar new
for (int i = 0; i < 20; i++) {
n[i] = (int)(Math.random() * 381) + 20;
System.out.println(n[i] + " ");
}
System.out.println("\n¿Qué números quiere resaltar? "); // ln porque es string
System.out.print("(1 – los múltiplos de 5, 2 – los múltiplos de 7): ");
int opcion = Integer.parseInt(System.console().readLine());
int multiplo = (opcion == 1) ? 5 : 7; // operador ternario
for (int e : n) { // es int porque son enteros
if (e % multiplo == 0) {
System.out.print("[" + e + "] ");
} else {
System.out.print(e + " ");
}
}
}
}