Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 7, 2019 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/cd939ceb9bc0f4cb1a835e521aa4236a to your computer and use it in GitHub Desktop.
Save parzibyte/cd939ceb9bc0f4cb1a835e521aa4236a to your computer and use it in GitHub Desktop.
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