Your SlideShare is downloading. ×
El Numero Primo
El Numero Primo
El Numero Primo
El Numero Primo
El Numero Primo
El Numero Primo
El Numero Primo
El Numero Primo
El Numero Primo
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

El Numero Primo

6,388

Published on

Un ejemplo en donde se puede ver como se resuelve una serie de números primos paso a paso

Un ejemplo en donde se puede ver como se resuelve una serie de números primos paso a paso

Published in: Technology, Travel
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,388
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
74
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1.
    • Halla los N número primos
    • Verificar si un número es primo
  • 2. package uno; import javax.swing.JOptionPane; public class primo { static int d = 2; }
  • 3. El siguiente método lo comprueba
  • 4. static boolean verificar(int n) { boolean v = true; d = 2; while (d < n && v == true) { if (n % d == 0) { v = false; } else { d++; } } return v; }
  • 5. static int leer() { String mj = JOptionPane.showInputDialog(null, &quot;ingrese numero&quot;, &quot;ingreso&quot;, JOptionPane.QUESTION_MESSAGE); return (Integer.parseInt(mj)); }
  • 6. static int leer2() { String mj = JOptionPane.showInputDialog(null, &quot;ingrese limite de la serie&quot;, &quot;ingreso&quot;, JOptionPane.QUESTION_MESSAGE); return (Integer.parseInt(mj)); }
  • 7. static void medodo_1(int n) { boolean v = verificar(n); if (v == true) { JOptionPane.showMessageDialog(null, &quot;el &quot; + n + &quot; es primo&quot;, &quot;respuesta&quot;,JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, &quot;el &quot; + n + &quot; no es primo es divisible a: &quot;+d, &quot;respuesta&quot;, JOptionPane.ERROR_MESSAGE); } }
  • 8. static void medodo_2(int n) { int in = 0; int i = 0; while (i < n) { in++; boolean v = verificar(in); if (v == true) { JOptionPane.showMessageDialog(null, &quot;el &quot; + in + &quot; es primo va en el # &quot; + (i + 1), &quot;respuesta&quot;, JOptionPane.INFORMATION_MESSAGE); i++; } } }
  • 9. public static void main(String[] args) { String mj = JOptionPane.showInputDialog(null, &quot;ingrese opcion deseada '1' para verificar si un numero es primo '2' para sacar la serie de N #s primos&quot;, &quot;ingreso&quot;, JOptionPane.QUESTION_MESSAGE); switch (mj.charAt(0)) { case '1': medodo_1(leer()); break; case '2': medodo_2(leer2()); break; default: JOptionPane.showMessageDialog(null, &quot;ingreso mal la opcion&quot;, &quot;falla&quot;, JOptionPane.ERROR_MESSAGE); break; } }

×