El Numero Primo

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Group

    El Numero Primo - Presentation Transcript

      • Halla los N n煤mero primos
      • Verificar si un n煤mero es primo
    1. package uno; import javax.swing.JOptionPane; public class primo { static int d = 2; }
    2. El siguiente m茅todo lo comprueba
    3. 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; }
    4. static int leer() { String mj = JOptionPane.showInputDialog(null, &quot;ingrese numero&quot;, &quot;ingreso&quot;, JOptionPane.QUESTION_MESSAGE); return (Integer.parseInt(mj)); }
    5. 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)); }
    6. 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); } }
    7. 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++; } } }
    8. 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; } }

    + eccutpleccutpl, 2 years ago

    custom

    2320 views, 0 favs, 0 embeds more stats

    Un ejemplo en donde se puede ver como se resuelve u more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 2320
      • 2320 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 27
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Groups / Events