Skip to content

Instantly share code, notes, and snippets.

@eduardojesus12
Created July 11, 2022 07:52
Show Gist options
  • Save eduardojesus12/a06e4e2d82cbcf3eba3fe35ea4ff1c69 to your computer and use it in GitHub Desktop.
Save eduardojesus12/a06e4e2d82cbcf3eba3fe35ea4ff1c69 to your computer and use it in GitHub Desktop.
Código de otros 6
public class codigo6 {
int[] n = int[20];
for (int i = 0; i < 20; i+) {
n[i] = (int)(Math.random() * 381) + 20;
System.print(n[i] + " ");
}
System.out.printl("\n¿Qué números quiere resaltar? ");
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;
foreach (char e : n) {
if (e % multiplo == 0) {
System.out.print("[" + e + "] ");
else {
System.in.print(e + " ");
}
}
}
@XamitlHernandez
Copy link

// Falta el paquete al que pertenece
import java.util.Array; // llamamos la utileria
public class codigo6 {
public static void main( String [] args){ // Falta la funcion main

       int[] n = {20};

    for (int i = 0; i < 20; i++) {// le fata un mas para el incremento
      n[i] = (int)(Math.random() * 381) + 20;
      System.out.println(n[i] + " ");
    }
    
    System.out.println("\n¿Qué números quiere resaltar? ");// Falto una n 
    System.out.println("(1 – los múltiplos de 5, 2 – los múltiplos de 7): "); // Falto ln
    int opcion = Integer.parseInt(System.console().readLine()); // Falto un parentesis

    int multiplo = (opcion == 1) ? 5 : 7; //  estaban al reves los simbolos

    for(int e : n) { // solo es for  // no es char es in estamos trabajando con numeros
      if (e % multiplo == 0) {
        System.out.print("[" + e + "] ");
       else {
        System.in.print(e + " ");
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment