Tecnología y ElectrónicaBásico1 respuestas

Necesito HACER un PROGRAMA QUE PIDA DOS NUMEROS Y QUE IMPRIMA EL ACUMULADO A PARTIR DEL PRIMER HASTA EL SEGUNDO NUMERO INTRODUCIDO Ejemplo digito 2 y 5, debe mostrar : 3 4 y su suma es 7?

Necesito HACER un PROGRAMA QUE PIDA DOS NUMEROS Y QUE IMPRIMA EL ACUMULADO A PARTIR DEL PRIMER HASTA EL SEGUNDO NUMERO INTRODUCIDO Ejemplo digito 2 y 5, debe mostrar : 3 4 y su suma es 7. Si alguien sabe por favor necesito ayuda ahora.

En resumen

Solución básicaen Java privateArrayList consecutivos = new ArrayList() ; public void obtenerConsecutivos() { int acumulado = obtenerAcumulado(2, 5) ; if (this. Consecutivos. Length ! = 0) { for (int num : this. Consecutivos) { console. Log(num + "") ; } console.

Mejor respuesta

Piringo
7

Solución básicaen Java

privateArrayList consecutivos = new ArrayList() ;

public void obtenerConsecutivos() { int acumulado = obtenerAcumulado(2, 5) ; if (this.

Consecutivos.

Length !

= 0) { for (int num : this.

Consecutivos) { console.

Log(num + "") ; } console.

Log(" \ n Su suma es" + acumulado) ; }

}

private int obtenerAcumulado (int a, int b) { int total = 0 ; for (int i = a + 1 ; i< b ; i + + ) { this.

Consecutivos.

Add(i) ; total + = i ; } return total ;

}.