Created
May 29, 2024 13:03
-
-
Save davidmanueldev/5de5f7362b7b5c0d35c2bf975c906517 to your computer and use it in GitHub Desktop.
Ejercicios con listas dobles
This file contains hidden or 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
| // 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