Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

77
Views
Principiante. ¿Alguien puede enseñarme cómo contar la cantidad de veces que se ha ejecutado el ciclo interno?

¿Alguien puede enseñarme cómo contar la cantidad de veces que se ha ejecutado el ciclo interno?

 import java.util.*; public class Lab8Ex5{ public static void main(String[] args){ int primeCount = 1; System.out.print(2); int num = 2; while (primeCount < 20){ num++; // try next number boolean isPrime = true; for (int i = 2; i < num; i++){ if(num%i==0) // divisible by i isPrime = false; // not a prime } if (isPrime){ primeCount++; // one more prime is found System.out.print(","+num); } } System.out.println("Done"); } }

El número de conteos debe ser 2415. Sé que int count = 0; para (...) contar++; puede ser usado. Sin embargo, no sé dónde debería poner eso.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Debe definir un contador fuera de los bucles.

Luego, debe incrementar el contador dentro del bucle anidado.

Contará el número de ejecuciones del bucle anidado sobre el bucle exterior.

 import java.util.*; public class Lab8Ex5{ public static void main(String[] args){ int primeCount = 1; System.out.print(2); int num = 2; int counter = 0; // Define the counter and init it while (primeCount < 20){ num++; // try next number boolean isPrime = true; for (int i = 2; i < num; i++){ counter++; // Increment the counter in the inner loop if(num%i==0) // divisible by i isPrime = false; // not a prime } if (isPrime){ primeCount++; // one more prime is found System.out.print(","+num); } } // Print the value of counter System.out.println("Done in " + counter + " steps"); } }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!