-
-
Save parzibyte/cd939ceb9bc0f4cb1a835e521aa4236a 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); | |
return ((maximo + minimo) * (maximo + 1 - minimo)) / 2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment