parece el tipico profesor aburrido de toda la bendita vida. v cuidado con esopackage foro;
import java.security.SecureRandom;
import java.util.HashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.logging.Logger;
public class ArrayConFormato {
private static final Logger LOGGER = Logger.getLogger(ArrayConFormato.class.getName());
public static void main
(String ...
gaga) {
//una manera de hacerlo
final Set<Integer> num = new HashSet<>();
num.add(1);
num.add(2);
num.add(3);
num.add(4);
LOGGER.info("Array " +num);
//otra manera de hacerlo
final SortedSet<Integer> num2 = new TreeSet<>();
num2.add(1);
num2.add(2);
num2.add(3);
num2.add(4);
LOGGER.info("Array " +num2);
final int[] numeros = new int[5];
for(int f=0; f<numeros.length; f++) {
numeros[f] = getPseudoRandom();
}
// aqui creo un array de 5 indices, aleatorios
// y le concateno una coma
final StringBuilder sb = new StringBuilder("[");
for(int f=0; f<numeros.length; f++) {
sb.append(numeros[f]);
sb.append(",");
}
//al final le borro la coma, la ultima, y le concateno el ]
final String XD
= sb.
delete(sb.
length()-1,sb.
length()).
append("]").
toString(); LOGGER.info(XD);
}
private static int getPseudoRandom() {
return 1 + SR.nextInt(11);
}
}
Jan 14, 2019 10:07:18 PM ArrayConFormato main
INFORMACIÓN: Array [1, 2, 3, 4]
Jan 14, 2019 10:07:18 PM ArrayConFormato main
INFORMACIÓN: Array [1, 2, 3, 4]
Jan 14, 2019 10:07:19 PM ArrayConFormato main
INFORMACIÓN: [6,7,6,4,7]
Process finished with exit code 0