TP_Sem11

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Caso 01:

import java.util.Scanner;

public class MatrizSumaPromedio {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

double[][] matriz = new double[3][3];

double[] sumas = new double[3];

double[] promedios = new double[3];

System.out.println("Ingresa los números para la matriz 3x3:");

for (int i = 0; i < 3; i++) {

for (int j = 0; j < 3; j++) {

System.out.print("Elemento [" + i + "][" + j + "]: ");

matriz[i][j] = scanner.nextDouble();

for (int i = 0; i < 3; i++) {

double sumaFila = 0;

for (int j = 0; j < 3; j++) {

sumaFila += matriz[i][j];

sumas[i] = sumaFila;

promedios[i] = sumaFila / 3;

System.out.println("\nResultados:");

for (int i = 0; i < 3; i++) {

System.out.println("Fila " + (i + 1) + ": Suma = " + sumas[i] + ", Promedio = " +


promedios[i]);

}
Caso 02:
package tp_sem11;

import java.util.Arrays;

public class Caso02 {

public static void main(String[] args) {

String[] nombres = {"Ana", "Carlos", "Beatriz", "Daniel"};

int[] edades = {20, 22, 21, 23};

double[][] notas = {

{15.0, 18.0, 12.0, 20.0},

{10.0, 11.5, 14.0, 16.0},

{17.0, 20.0, 15.5, 19.0},

{12.0, 13.5, 14.0, 15.0}

};

double[] promedios = new double[nombres.length];

double sumaTotalPromedios = 0;

for (int i = 0; i < notas.length; i++) {

double suma = 0;

for (int j = 0; j < notas[i].length; j++) {


suma += notas[i][j];

promedios[i] = suma / notas[i].length;

sumaTotalPromedios += promedios[i];

double promedioTotal = sumaTotalPromedios / nombres.length;

for (int i = 0; i < nombres.length - 1; i++) {

for (int j = i + 1; j < nombres.length; j++) {

if (nombres[i].compareTo(nombres[j]) > 0) {

String tempNombre = nombres[i];

nombres[i] = nombres[j];

nombres[j] = tempNombre;

int tempEdad = edades[i];

edades[i] = edades[j];

edades[j] = tempEdad;

double[] tempNotas = notas[i];

notas[i] = notas[j];

notas[j] = tempNotas;

double tempPromedio = promedios[i];

promedios[i] = promedios[j];

promedios[j] = tempPromedio;

System.out.println("######### Reporte de Notas #########");

System.out.println("Nombre\tEdad\tPC1\tPC2\tPC3\tEF\tPromedio");

System.out.println("###################################");

for (int i = 0; i < nombres.length; i++) {

System.out.printf("%s\t%d\t%.1f\t%.1f\t%.1f\t%.1f\t%.2f\n",
nombres[i], edades[i], notas[i][0], notas[i][1], notas[i][2], notas[i][3], promedios[i]);

System.out.println("###################################");

System.out.printf("Promedio Total: %.2f\n", promedioTotal);

You might also like