-
-
Save parzibyte/a5d6b7abbf9ebc52f6552379b6418f65 to your computer and use it in GitHub Desktop.
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
class Main { | |
public static void main(String[] args) { | |
int inicio = 1, fin = 3; | |
System.out.printf("Inicio: %d. Fin: %d\n", inicio, fin); | |
System.out.printf("sumatoriaEnRango(%d, %d): %d\n", inicio, fin, sumatoriaEnRango(inicio, fin)); | |
System.out.printf("sumatoriaEnRango(%d, %d): %d\n", fin, inicio, sumatoriaEnRango(fin, inicio)); | |
} | |
public static int sumatoriaEnRango(int numero1, int numero2) { | |
int minimo = Math.min(numero1, numero2); | |
int maximo = Math.max(numero1, numero2); | |
int suma = 0; | |
for (int i = minimo; i <= maximo; i++) { | |
suma += i; | |
} | |
return suma; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment