Está en la página 1de 2

Lenguaje Java Guía 16 – Vectore Matrices Guía 16 – Vectore Matrices Lenguaje Java

76 73
JOptionPane.showMessageDialog(null," La suma de los elementos de la matriz es : Vectores y Matrices
"+suma+"\n La resta de los elementos de la matriz es : "+resta+"\n La multiplicaion de los Introduccion
elementos de la matriz es : "+multi+"\n La media aritmetica de los elementos de la matriz Programa complejo de consola, en java, para tratar vectores y matrices.
es : "+prom); Práctica 104
for( i=0; i<f; i++){ //Lee la Matrix import java.io.*;
for( j=0; j<c; j++){ import javax.swing.JOptionPane;
if(mat[i][j]>mayor){ public class Vecmat {
mayor=mat[i][j]; public static void main(String args[]) {
} String t="";
} int mayor=0;
} int menor=0;
JOptionPane.showMessageDialog(null," El mayor valor de la matriz es "+mayor); double suma=0;
menor=mayor; int resta=0;
for( i=0; i<f; i++){ //Lee la Matrix int multi=1;
for( j=0; j<c; j++){ boolean sw=false;
if(mat[i][j]<menor){ int j=0;
menor=mat[i][j]; int z=1;
} int cont=0;
} int conti=0;
} JOptionPane.showMessageDialog(null," :) B i E n V e N i D o S :) ");
JOptionPane.showMessageDialog(null," El menor valor de la matriz es "+menor); JOptionPane.showMessageDialog(null," :) VAMOS A TRABAJAR CON VECTORES Y MATRICES
for( i=0; i<f; i++){ //Lee la Matrix :) ");
for( j=0; j<c; j++){ JOptionPane.showMessageDialog(null," :) COMENCEMOS :) ");
if(mat[i][j]%2==0) while(z==1){
{ t="";
JOptionPane.showMessageDialog(null," El numero "+mat[i][j]+" es par y su posición es int m;
"+i+","+j); mayor=0;
cont++; int k=0;
} String s;
} menor=0;
} suma=0;
conti=(f*c)-cont; resta=0;
JOptionPane.showMessageDialog(null," La cantidad de numeros pares es : "+cont+"\n La multi=1;
cantidad de numeros impares es : "+conti ); sw=false;
} int i;
s=JOptionPane.showInputDialog(" DESEA SEGUIR TRABAJANDO CON VECTORES Y j=0;
MATRICES? \n 1. SI \n 2. NO"); z=1;
z=Integer.parseInt(s); cont=0;
conti=0;
} String op=JOptionPane.showInputDialog(" INGRESE 1 PARA CREAR VECTOR \n INGRESE 2
JOptionPane.showMessageDialog(null," :) GRACIAS POR VISITAR NUESTRO PROGRAMA \n PARA CREAR UNA MATRIZ ");
TE ESPERAMOS EN LA PROXIMA :) "); int ca=Integer.parseInt (op);
JOptionPane.showMessageDialog(null," :) CHAO :) "); switch (ca){
}//fin del main case 1:
}//fin de la clase JOptionPane.showMessageDialog(null," ***HAS SELECCIONADO LA OPCIÓN 1, AHORA
CREAREMOS UN VECTOR!!!*** ");
String tam=JOptionPane.showInputDialog(" Ingrese el tamaño deseado del vector :");
int n=Integer.parseInt (tam);
int[] vec=new int[n];

www.dariolara.com www.dariolara.com
Lenguaje Java Guía 16 – Vectore Matrices Guía 16 – Vectore Matrices Lenguaje Java
74 75
for(i=0;i<n;i++){ int numb=Integer.parseInt(vb);
String dato=JOptionPane.showInputDialog(" Ingrese los elementos del vector : "); for(i=0;i<n;i++){
vec[i]=Integer.parseInt(dato); if(numb==vec[i]){
System.out.print(vec[i]+" "); n=i;
} sw=true;
}else{
JOptionPane.showMessageDialog(null," VAMOS A CALCULAR LA SUMA, RESTA, sw=false;
MULTIPLICACIÓN Y PROMEDIO; \n LUEGO HALLAREMOS EL MAYOR Y EL MENOR NUMERO }
CON SUS RESPECTIVAS POSICIONES \n LOS PARES CON SU POSICIÓN Y EL TOTAL DE PARES }
E IMPARES \n BUSCAREMOS UN VALOR DENTRO DEL VECTOR "); if(sw==true){
for(i=0;i<n;i++){ JOptionPane.showMessageDialog(null," El numero "+numb+" si se encuentra dentro del
suma=suma+vec[i]; vector y esta en la posicion "+n);
resta=vec[i]-resta; }else{
multi=multi*vec[i]; JOptionPane.showMessageDialog(null," El numero "+numb+" no se encuentra dentro del
} vector ");
double prom=suma/n; }
JOptionPane.showMessageDialog(null," La suma de los elementos del vector es : break;
"+suma+"\n La resta de los elementos del vector es : "+resta+"\n La multiplicaion de los case 2:
elementos del vector es : "+multi+"\n La media aritmetica de los elementos del vector es : JOptionPane.showMessageDialog(null," ***HAS SELECCIONADO LA OPCIÓN 2, AHORA
"+prom); CREAREMOS UNA MATRIZ!!!*** ");
for(i=0;i<n;i++){ String fil=JOptionPane.showInputDialog(" INGRESE NUMERO DE FILAS ");
if(vec[i]>mayor){ int f=Integer.parseInt (fil);
mayor=vec[i]; String col=JOptionPane.showInputDialog(" INGRESE NUMERO DE COLUMNAS ");
j=i; int c=Integer.parseInt (col);
} int mat[][] = new int[f][c];
} for( i=0; i<f; i++){ //Lee la Matrix
JOptionPane.showMessageDialog(null," El mayor valor del vector es "+mayor+" y esta en la for( j=0; j<c; j++){
posicion "+j); String num=JOptionPane.showInputDialog(" INGRESE LOS ELEMENTOS DE LA MATRIZ ");
menor=mayor; mat[i][j]=Integer.parseInt(num);
for(i=0;i<n;i++){ }
if(vec[i]<menor){ }
menor=vec[i]; for (i=0; i<f; i++){ //Escribe la matrix
k=i; for(j=0; j<c; j++){
} t=t+mat[i][j]+' ';
} }
JOptionPane.showMessageDialog(null," El menor valor del vector es "+menor+" y esta en la System.out.println(t);
posicion "+k); t="";
for(i=0;i<n;i++){ }
if(vec[i]%2==0){ JOptionPane.showMessageDialog(null," VAMOS A CALCULAR LA SUMA, RESTA,
JOptionPane.showMessageDialog(null," El numero "+vec[i]+" es par y esta en la posicion MULTIPLICACIÓN Y PROMEDIO; \n LUEGO HALLAREMOS EL MAYOR \n LOS PARES CON SU
"+i); POSICIÓN Y EL TOTAL DE PARES E IMPARES ");
cont++; for( i=0; i<f; i++){ //Lee la Matrix
} for( j=0; j<c; j++){
} suma=suma+mat[i][j];
conti=n-cont; resta=mat[i][j]-resta;
JOptionPane.showMessageDialog(null," La cantidad de numeros pares es : "+cont+"\n La multi=multi*mat[i][j];
cantidad de numeros impares es : "+conti ); }
String vb=JOptionPane.showInputDialog(" INGRESE EL ELEMENTO A BUSCAR EN EL VECTOR }
"); prom=suma/(f*c);

www.dariolara.com www.dariolara.com

También podría gustarte