You are on page 1of 13

ob1.

llenar(mat1, tam);

ob1.llenar(mat2, tam);

System.out.println("Imprimiremos ambas matrices");

ob1.imprimir(mat1, tam);

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

ob1.imprimir(mat2, tam);

System.out.println("-----Hallaremos su matriz del producto--------\n");

int [][] rpta= new int[tam][tam];

ob1.multi(mat1, mat2, rpta, tam);

ob1.imprimir(rpta, tam);

Compilación
run:

---------->Pedimos los tamaños de la matrices <----------

Ingresa el tamaño de las matrices:

Imprimiremos ambas matrices

305

154
188

///////////////////////////////////

808

157

511

-----Hallaremos su matriz del producto--------

49 5 29

33 29 47

56 48 72

BUILD SUCCESSFUL (total time: 1 second)

Problema3
package javaapplication5;

import java.util.Random;

import java.util.Scanner;

public class Problema3 {

Scanner sc = new Scanner(System.in);

Random azar = new Random();

int aux1=0 , aux2=0 , aux3=0 ;

public int lx1(int x1){

System.out.println("Ingrese coef.variable X");

x1=sc.nextInt();

return x1;

public int ly1(int y1){

System.out.println("Ingrese coef.variable Y");

y1=sc.nextInt();
return y1;

public int lz1(int z1){

System.out.println("Ingrese coef.variable Z");

z1=sc.nextInt();

return z1;

public int ly2(int y2){

System.out.println("Ingrese coef.variable Y");

y2=sc.nextInt();

return y2;

public int lz2(int z2){

System.out.println("Ingrese coef.variable Z");

z2=sc.nextInt();

return z2;

public int lz3(int z3){

System.out.println("Ingrese coef.variable Z");

z3=sc.nextInt();

return z3;

public void a1(){

aux1=0+azar.nextInt(9);

public void a2(){

aux2=0+azar.nextInt(9);
}

public void a3(){

aux3=0+azar.nextInt(9);

public void sistema(int x1,int y1,int z1,int y2,int z2, int z3){

System.out.print(x1+"X"+" + "+y1+"Y"+" + "+z1+"Z"+" = "+aux1);

System.out.println("");

System.out.print(y2+"Y"+" + "+z2+"Z"+" = "+aux2);

System.out.println("");

System.out.println(z3+"Z"+" = "+aux3);

public void llenado(int mat[][], int x1 , int y1 ,int z1 , int y2 , int z2 , int z3){

mat[0][0]=x1 ;

mat[0][1]=y1;

mat[0][2]=z1;

mat[1][0]=0;

mat[1][1]=y2;

mat[1][2]=z2;

mat[2][0]=0;

mat[2][1]=0;

mat[2][2]=z3;

public double det(int x1 , int y2 , int z3){

int det ;

det=x1*y2*z3;

System.out.print(" : "+det);
return det ;

public void arr(int array[]){

array[0]=aux1;

array[1]=aux2;

array[2]=aux3;

public int hdx(int mat[][], int array[]){

int dx=0, auxa=0 , auxb=0 ;

int n1 , n2 , n3 ;

n1=mat[0][0];

n2=mat[1][0];

n3=mat[2][0];

mat[0][0]=array[0];

mat[1][0]=array[1];

mat[2][0]=array[2];

auxa=mat[0][0]*mat[1][1]*mat[2][2]+mat[1][0]*mat[2][1]*mat[0][2]+mat[2][0]*mat[0][1]*mat[1][2];

auxb=mat[0][2]*mat[1][1]*mat[2][0]+mat[1][2]*mat[2][1]*mat[0][0]+mat[2][2]*mat[0][1]*mat[1][0];

dx=auxa-auxb;

mat[0][0]=n1;

mat[1][0]=n2;

mat[2][0]=n3;

System.out.println(": "+dx);

return dx;
}

public int hdy(int mat[][], int array[]){

int dy=0, auxa=0 , auxb=0 ;

int n1 , n2 , n3 ;

n1=mat[0][1];

n2=mat[1][1];

n3=mat[2][1];

mat[0][1]=array[0];

mat[1][1]=array[1];

mat[2][1]=array[2];

auxa=mat[0][0]*mat[1][1]*mat[2][2]+mat[1][0]*mat[2][1]*mat[0][2]+mat[2][0]*mat[0][1]*mat[1][2];

auxb=mat[0][2]*mat[1][1]*mat[2][0]+mat[1][2]*mat[2][1]*mat[0][0]+mat[2][2]*mat[0][1]*mat[1][0];

dy=(auxa-auxb);

mat[0][1]=n1;

mat[1][1]=n2;

mat[2][1]=n3;

System.out.println(": "+dy);

return dy;

public int hdz(int mat[][], int array[]){

int dz=0, auxa=0 , auxb=0 ;

int n1 , n2 , n3 ;

n1=mat[0][2];

n2=mat[1][2];
n3=mat[2][2];

mat[0][2]=array[0];

mat[1][2]=array[1];

mat[2][2]=array[2];

auxa=mat[0][0]*mat[1][1]*mat[2][2]+mat[1][0]*mat[2][1]*mat[0][2]+mat[2][0]*mat[0][1]*mat[1][2];

auxb=mat[0][2]*mat[1][1]*mat[2][0]+mat[1][2]*mat[2][1]*mat[0][0]+mat[2][2]*mat[0][1]*mat[1][0];

dz=auxa-auxb;

mat[0][2]=n1;

mat[1][2]=n2;

mat[2][2]=n3;

System.out.println(": "+dz);

return dz;

public void rf(double det , double dx , double dy , double dz){

System.out.println("Valor de x: "+(dx/det));

System.out.println("Valor de y: "+(dy/det));

System.out.println("Valor de z: "+(dz/det));

package javaapplication5;

public class Principal3 {

public static void main(String[] args) {

Problema3 ob1 = new Problema3();

int x1 = 0 , y1 = 0, z1 = 0;
int y2 = 0 , z2 = 0;

int z3 = 0;

double det=0 , dx=0 , dy=0 , dz=0 ;

x1=ob1.lx1(x1);

y1=ob1.ly1(y1);

z1=ob1.lz1(z1);

y2=ob1.ly2(y2);

z2=ob1.lz2(z2);

z3= ob1.lz3(z3);

ob1.a1();

ob1.a2();

ob1.a3();

System.out.println("---->Imprimiremos El sistema de Ecuaciones------------<");

System.out.println("");

ob1.sistema(x1,y1, z1,y2,z2, z3);

int[][] mat = new int[3][3];

ob1.llenado(mat, x1, y1, z1, y2, z2, z3);

System.out.println("Determinante de la matriz principal : ");

det=ob1.det(x1, y2, z3);

int [] array = new int[3];

ob1.arr(array);

System.out.println("\nDeterminante de la variable'x' : ");

dx=ob1.hdx(mat, array);

System.out.println("Determinante de la variable'y' : ");


dy=ob1.hdy(mat, array);

System.out.println("Determinante de la variable'z' : ");

dz=ob1.hdz(mat, array);

System.out.println("---<<Hallando resultados finales>>---");

ob1.rf(det, dx, dy, dz);

Compilación
run:

Ingrese coef.variable X

Ingrese coef.variable Y

Ingrese coef.variable Z

Ingrese coef.variable Y

Ingrese coef.variable Z

Ingrese coef.variable Z

---->Imprimiremos El sistema de Ecuaciones------------<

5X + 6Y + 4Z = 1

1Y + 9Z = 6

5Z = 8

Determinante de la matriz principal :


: 25

Determinante de la variable'x' :

: 225

Determinante de la variable'y' :

: -210

Determinante de la variable'z' :

: 40

---<<Hallando resultados finales>>---

Valor de x: 9.0

Valor de y: -8.4

Valor de z: 1.6

BUILD SUCCESSFUL (total time: 11 seconds)

Problema 4
package javaapplication5;

import java.util.Scanner;

public class Problema4 {

Scanner sc = new Scanner(System.in);

public void nombres(String array[]){

System.out.println("Ingrese los nombres de los alumnos: ");

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

array[i]=sc.nextLine();

public void notas(String arrnot1[]){

System.out.println("Ingrese las notas de los alumnos: ");

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

arrnot1[i]=sc.nextLine();
}

public void pasar(String array[] , String arrnot1[] , String matriz[][]){

matriz[0][0]=array[0];

matriz[1][0]=array[1];

matriz[2][0]=array[2];

matriz[3][0]=array[3];

matriz[0][1]=" 10.2 ";//Conversion de Decimal a String

matriz[1][1]="11.4";//Conversion de Decimal a String

matriz[2][1]="12.8";//Conversion de Decimal a String

matriz[3][1]="14.6";//Conversion de Decimal a String

public void mostrar1(String matriz[][]){

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

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

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

}System.out.println("");

public void ordenar(String matriz[][]){

System.out.print(matriz[3][0]+" : "+matriz[3][1]);

System.out.println("");
System.out.print(matriz[2][0]+" : "+matriz[2][1]);

System.out.println("");

System.out.print(matriz[1][0]+" : "+matriz[1][1]);

System.out.println("");

System.out.print(matriz[0][0]+" : "+matriz[0][1]);

System.out.println("");

package javaapplication5;

public class Principal4 {

public static void main(String[] args) {

Problema4 ob1 = new Problema4();

String [] array = new String[4];

String [] arrnot1 = new String[4];

double [] arrnot2=new double[4];

String [][] matriz = new String[4][4];

ob1.nombres(array);

ob1.pasar(array, arrnot1, matriz);

System.out.println("----->Las notas con nombres son : ");

ob1.mostrar1(matriz);

System.out.println("------>Notas ordenadas son : ");

ob1.ordenar(matriz);

}
}

Compilación
run:

Ingrese los nombres de los alumnos:

jairo

luis

abel

juan

----->Las notas con nombres son :

jairo 10.2

luis 11.4

abel 12.8

juan 14.6

------>Notas ordenadas son :

juan : 14.6

abel : 12.8

luis : 11.4

jairo : 10.2

BUILD SUCCESSFUL (total time: 10 seconds)

You might also like