elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a Git (Primera Parte)


  Mostrar Temas
Páginas: [1]
1  Programación / Java / Que esta mal en este codigo o que me falta??? JAVA es con recursividad en: 15 Septiembre 2018, 01:36 am
Código
  1.  
  2. public class Primos {
  3.  
  4.    public static int SumaArreglo(int a[]) {
  5.        return SumaArreglo(a, a.length - 1);
  6.    }
  7.  
  8.    public static int SumaArreglo(int a[], int i) {
  9.        if (i == 0)
  10.        {
  11.        return a[0];
  12.        }
  13.         else if (Primo(a[i]) == true) {
  14.            return a[i] + SumaArreglo(a, i - 1);
  15.        } else {
  16.            return SumaArreglo(a, i - 1);
  17.        }
  18.    }
  19.  
  20.    public static boolean Primo(int n, int contador) {
  21.  
  22.        if (contador == 1) {
  23.            return true;
  24.        } else if (n % contador == 0) {
  25.            return false;
  26.        } else {
  27.            return Primo(n, contador - 1);
  28.        }
  29.    }
  30.  
  31.    public static boolean Primo(int n) {
  32.        if (n == 1) {
  33.            return true;
  34.        } else {
  35.            return Primo(n, n / 2);
  36.        }
  37.    }
  38.  
  39.    public static void main(String[] args) {
  40.        int A[] = {10,7,8,23,9,2};
  41.        showMessageDialog(null, SumaArreglo(A));
  42.    }
  43. }
  44.  
  45.  

[MOD] para publicar código se usan las etiquetas GeSHi.
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines