Skip to content

Instantly share code, notes, and snippets.

@davidmanueldev
Created May 29, 2024 13:03
Show Gist options
  • Select an option

  • Save davidmanueldev/5de5f7362b7b5c0d35c2bf975c906517 to your computer and use it in GitHub Desktop.

Select an option

Save davidmanueldev/5de5f7362b7b5c0d35c2bf975c906517 to your computer and use it in GitHub Desktop.
Ejercicios con listas dobles
// Ejercicios de listas dobles
// Ejercicio 1: Hallar el promedio del primer elemento con el último
import java.util.Scanner;
public class App {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int n;
System.out.println("Ingrese el tamaño de la lista: ");
n = sc.nextInt();
int[] lista = new int[n];
int i = 0;
while (i < n) {
System.out.println("Ingrese el elemento " + (i + 1) + ": ");
lista[i] = sc.nextInt();
i++;
}
System.out.println("El promedio del primer elemento con el último es: " + promedio(lista));
}
public static double promedio(int[] lista) {
return (double) (lista[0] + lista[lista.length - 1]) / 2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment