
Ayuda tengo un proyecto
Publicado por daniel (1 intervención) el 05/12/2021 11:42:10
ayuda por favor llevo 2 dias haciendo este codigo pero no paso de la primera parte por favor lo tengo que entregar mañana alguien me puede ayudar con las siguientes partes? el problema es este
Escriba un programa que ponga números aleatorios menores a 100, en un vector de dos dimensiones de 5 por 4
Imprima los valores en pantalla en columnas. Se pide:
Calcular promedio de todos los números.
Mostrar el valor máximo y mínimo
Intercambiar los valores de la diagonal principal por los valores de la última columna.
Mostrar matriz modificada.
ya hice la parte de los promedios pero me faltanl los otros este es el codigo
package proyectofinaldos;
public class ProyectoFinalDos {
public static void main(String[] args) {
int filas = 5;
int columnas = 4;
int Filas = 5;
int Columnas = 4;
int[][] numero = new int[filas][columnas];
int matrizsec[][] = new int[Filas][Columnas];
int suma,salida=0;
int sumaTotal = 0;
int numero2,auxiliar,a=0;
System.out.println("Generación de números menores de forma aleatoria");
for (int i = 0; i < filas; i ++) {
suma = 0;
for (int j = 0; j < columnas; j ++) {
numero[i][j] = (int) (Math.random()* 100)+1;
System.out.print(numero[i][j] + "\t");
//Parte de la suma;
suma += numero[i][j];
a=numero[i][j];
}
System.out.println("Suma: " + suma);
}
for (int j = 0; j < columnas; j ++) {
suma = 0;
for (int i = 0; i < filas; i ++) {
suma += numero[i][j];
}
System.out.print("" + "\t");
sumaTotal += suma;
}
System.out.print("SumaTotal: " + sumaTotal);
System.out.println("");
System.out.println();
System.out.println("------------------------------------------------------------------------------------------------------");
for (int i = 0; i < filas; i ++) {
suma = 0;
for (int j = 0; j < columnas; j ++) {
int mayor, menor;
mayor = menor = numero[i][j];
for (int k = 0; k < numero[i][j]; k++) {
if(mayor > 100) {
salida=mayor;
}
if(100 <menor) {
salida =menor;
}
}
System.out.println("El mayor valor es: "+mayor);
System.out.println("El menor valor es: "+menor);
}
}
System.out.println("------------------------------------------------------------------------------------------------------");
int aux;
int b=0;
for (int i = 0; i < Filas; i ++) {
suma = 0;
for (int j = 0; j < Columnas; j ++) {
matrizsec[i][j] = (int) (Math.random()* 100)+1;
System.out.print(matrizsec[i][j] + "\t");
b=matrizsec[i][j] ;
}
System.out.println(" ");
}
System.out.println();
//mostrar valores
for (int i = 0; i < Filas; i++) {
for (int j = 0; j < Columnas; j++) {
System.out.println(matrizsec[i][j]);
}
System.out.println();
}
}
}



Escriba un programa que ponga números aleatorios menores a 100, en un vector de dos dimensiones de 5 por 4
Imprima los valores en pantalla en columnas. Se pide:
Calcular promedio de todos los números.
Mostrar el valor máximo y mínimo
Intercambiar los valores de la diagonal principal por los valores de la última columna.
Mostrar matriz modificada.
ya hice la parte de los promedios pero me faltanl los otros este es el codigo
package proyectofinaldos;
public class ProyectoFinalDos {
public static void main(String[] args) {
int filas = 5;
int columnas = 4;
int Filas = 5;
int Columnas = 4;
int[][] numero = new int[filas][columnas];
int matrizsec[][] = new int[Filas][Columnas];
int suma,salida=0;
int sumaTotal = 0;
int numero2,auxiliar,a=0;
System.out.println("Generación de números menores de forma aleatoria");
for (int i = 0; i < filas; i ++) {
suma = 0;
for (int j = 0; j < columnas; j ++) {
numero[i][j] = (int) (Math.random()* 100)+1;
System.out.print(numero[i][j] + "\t");
//Parte de la suma;
suma += numero[i][j];
a=numero[i][j];
}
System.out.println("Suma: " + suma);
}
for (int j = 0; j < columnas; j ++) {
suma = 0;
for (int i = 0; i < filas; i ++) {
suma += numero[i][j];
}
System.out.print("" + "\t");
sumaTotal += suma;
}
System.out.print("SumaTotal: " + sumaTotal);
System.out.println("");
System.out.println();
System.out.println("------------------------------------------------------------------------------------------------------");
for (int i = 0; i < filas; i ++) {
suma = 0;
for (int j = 0; j < columnas; j ++) {
int mayor, menor;
mayor = menor = numero[i][j];
for (int k = 0; k < numero[i][j]; k++) {
if(mayor > 100) {
salida=mayor;
}
if(100 <menor) {
salida =menor;
}
}
System.out.println("El mayor valor es: "+mayor);
System.out.println("El menor valor es: "+menor);
}
}
System.out.println("------------------------------------------------------------------------------------------------------");
int aux;
int b=0;
for (int i = 0; i < Filas; i ++) {
suma = 0;
for (int j = 0; j < Columnas; j ++) {
matrizsec[i][j] = (int) (Math.random()* 100)+1;
System.out.print(matrizsec[i][j] + "\t");
b=matrizsec[i][j] ;
}
System.out.println(" ");
}
System.out.println();
//mostrar valores
for (int i = 0; i < Filas; i++) {
for (int j = 0; j < Columnas; j++) {
System.out.println(matrizsec[i][j]);
}
System.out.println();
}
}
}



Valora esta pregunta


0