Created
January 13, 2012 04:37
-
-
Save benek/1604716 to your computer and use it in GitHub Desktop.
Coding Kata 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package codingdojo.numerosprimos; | |
/** | |
* @author benek | |
* Date: 12/01/12 | |
* Time: 20:57 | |
* www.javamexico.org | |
*/ | |
public class NumerosPrimos { | |
public static void main(String args[]){ | |
long inicio = System.currentTimeMillis(); | |
int i = 2; | |
int primo = 0; | |
for (;;){ | |
if (esPrimo(i)){ | |
primo++; | |
} | |
if (primo == 10001){ | |
break; | |
} | |
i++; | |
} | |
System.out.println(i); | |
long termino = System.currentTimeMillis(); | |
System.out.println(termino - inicio); | |
} | |
private static boolean esPrimo(int numero){ | |
if (numero == 2 || numero == 3){ | |
return true; | |
} else { | |
for (int i = 2; i <= (int) Math.sqrt(numero); i++){ | |
if (numero%i == 0){ | |
return false; | |
} | |
} | |
return true; | |
} | |
} | |
} |
Deberías de ir al siguiente Dojo ese Chochos :D...
Sí, pues a ver si al próximo...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yo sí ya lo medí aquí en local y efectivamente sale en el intervalo que mencionas "luego luego" aka "en chinga".