Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Laifsyn committed Apr 5, 2024
1 parent eebb063 commit 9d94342
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"configurations": [
{
"type": "java",
"name": "App",
"request": "launch",
"mainClass": "com.utp.clsHerramientas.pry1.App",
"projectName": "my-app"
},
{
"type": "java",
"name": "RepNumericas",
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/utp/clsHerramientas/_metadata.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[[proyectos]]
folder = "pry1"
name = "TEMA 2 – ACTIVIDAD 3"
submit_date = "04/14"
61 changes: 61 additions & 0 deletions src/main/java/com/utp/clsHerramientas/pry1/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.utp.clsHerramientas.pry1;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Optional;

// · Opción 1: Método llamado mtdListaNumeros, que determina la media de una lista indefinida de números positivos, terminados con un número negativo. La entrada y salidas deben realizarse dentro del método principal.
public class App {
public static void main(String[] args) {
ListaDeNumeros lista = new ListaDeNumeros();
Methods methods = new Methods();
System.out.println("La media de los números ingresados es: " + methods.mtdListaNumeros(lista));
methods.mtdFactorial(1);
methods.mtdFactorial(2);
methods.mtdFactorial(3);
methods.mtdFactorial(4);
methods.mtdFactorial(5);
methods.mtdFactorial(6);
}
}

class ListaDeNumeros {
ArrayList<Integer> Lista = new ArrayList<>();

ArrayList<Integer> getLista() {
return Lista;
}

Optional<Integer> push_str(String input) {
Optional<Integer> num = Optional.ofNullable(Integer.parseInt(input));
if (num.isPresent()) {
Lista.add(num.get());
}
return num;
}
}

class Methods {
public Optional<Double> mtdListaNumeros(ListaDeNumeros lista) {
if (lista.getLista().isEmpty()) {
return Optional.empty();
}
double sum = 0;
for (int item : lista.getLista()) {
sum += item;
}
return Optional.of(sum / lista.getLista().size());
}

// · Opción 2: Método llamado mtdFactorial que contenga el cálculo del factorial
// de un número leído en el método principal. La impresión del resultado se
// realiza en el método mtdFactorial.
public void mtdFactorial(int num) {
BigDecimal factorial = new BigDecimal(1);
for (int i = 1; i <= num; i++) {
factorial = factorial.multiply(new BigDecimal(i));
}
System.out.println("El factorial de " + num + " es: " + factorial);
}

}

0 comments on commit 9d94342

Please sign in to comment.