SlideShare une entreprise Scribd logo
1  sur  17
EJERCICIOS RESUELTOS DE JAVA>> ARITMETICA <<- Hallar A+B-C+100Código:class JavaAritmetica1{    public static void main (String mago [])    {int A, B, C;System.out.print (quot;
Inserte A: quot;
);A = Leer.datoInt ();System.out.print (quot;
Inserte B: quot;
);B = Leer.datoInt ();System.out.print (quot;
Inserte C: quot;
);C = Leer.datoInt ();System.out.println (quot;
quot;
 + A + quot;
 + quot;
 + quot;
 quot;
 + B + quot;
 - quot;
 + C + quot;
 + quot;
 + 100 + quot;
 = quot;
 + (A + B - C + 100));    }}Hallar (a-b)(a+b)Código:class JavaAritmetica2{    public static void main (String elMago [])    {int a, b;System.out.print (quot;
Inserte valor a: quot;
);a = Leer.datoInt ();System.out.print (quot;
Inserte valor b: quot;
);b = Leer.datoInt ();System.out.println (quot;
(quot;
 + a + quot;
-quot;
 + b + quot;
) quot;
 + quot;
(quot;
 + a + quot;
+quot;
 + b + quot;
) quot;
 + quot;
= quot;
 + ((a - b) * (a + b)));    }}Leer un numeo de tres digitos y sumarlosCódigo:class JavaAritmetica3{    public static void main (String elMago [])    {int numero, sumDig = 0;System.out.print (quot;
Inserte numero de tres digitos: quot;
);numero = Leer.datoInt ();if (numero <= 100)    System.out.println (quot;
ERROR: El numero no tiene 3 digitosquot;
);else{    int aux = numero; //en aux salvamos numero    while (numero != 0)    {sumDig = sumDig + (numero % 10); //sumamos a sumDig el ultimo digito de numeronumero = numero / 10; //eliminamos el ultimo digito de numero    }    System.out.println (quot;
La suma de los digitos de quot;
 + aux + quot;
 es: quot;
 + sumDig);}    }}Dado un numero verificar:    - Que tenga dos digitos    - Verificar si sus digitos son pares    - Promediar sus digitos Código:class JavaAritmetica4{    public static void main (String args [])    {int numero;System.out.print (quot;
Inserte un numero de dos digitos pares: quot;
);numero = Leer.datoInt ();int aux = numero;if (numero < 100 && numero > 9){    int d1 = numero % 10;    numero = numero / 10;    int d2 = numero % 10;    if (d1 % 2 == 0 && d2 % 2 == 0)System.out.println (quot;
El promedio de los digitos de: quot;
 + aux + quot;
 es: quot;
 + ((d1 + d2) / 2));}    }}Dado un numero entero, determinar si es positivo, negativo o nuloCódigo:class JavaAritmetica5{    public static void main (String args [])    {int numero;System.out.print (quot;
Inserte un numero: quot;
);numero = Leer.datoInt ();if (numero == 0)    System.out.println (quot;
El numero quot;
 + numero + quot;
 es NULOquot;
);else{    if (numero < 0)System.out.println (quot;
El numero quot;
 + numero + quot;
 es NEGATIVOquot;
);    elseSystem.out.println (quot;
El numero quot;
 + numero + quot;
 es POSITIVOquot;
);}    }}Dados seis numero determinar el menor de ellosCódigo:class JavaAritmetica6{    public static void main (String args [])    {int a, b, c, d, e, f;System.out.print (quot;
Inserte num.1: quot;
);a = Leer.datoInt ();System.out.print (quot;
Inserte num.2: quot;
);b = Leer.datoInt ();System.out.print (quot;
Inserte num.3: quot;
);c = Leer.datoInt ();System.out.print (quot;
Inserte num.4: quot;
);d = Leer.datoInt ();System.out.print (quot;
Inserte num.5: quot;
);e = Leer.datoInt ();System.out.print (quot;
Inserte num.6: quot;
);f = Leer.datoInt ();int menor = a;if (b < menor)    menor = b;if (c < menor)    menor = c;if (d < menor)    menor = d;if (e < menor)    menor = e;if (f < menor)    menor = f;System.out.println (quot;
El menor de:quot;
 + a + quot;
,quot;
 + b + quot;
,quot;
 + c + quot;
,quot;
 + d + quot;
,quot;
 + e + quot;
,quot;
 + f + quot;
,quot;
);System.out.println (quot;
Es: quot;
 + menor);    }}<br />>> SERIES <<Generar 5,10,15,20,25,30,...Código:class JavaSeries1{    public static void main (String args [])    {int n, c = 1, serie = 5;System.out.print (quot;
Cantidad d terminos: quot;
);n = Leer.datoInt ();while (c <= n){    System.out.print (quot;
,quot;
 + serie);    serie += 5;    c++;}    }}Si n=7  generar 7,6,5,4,3,2,1    Código:class JavaSeries2{    public static void main (String args [])    {int n, c = 1;System.out.print (quot;
Cantidad d terminos: quot;
);n = Leer.datoInt ();int serie = n;while (c <= n){    System.out.print (serie + quot;
,quot;
);    serie--;    c++;}    }}<br />>> VECTORES <</*Dado el vector T de tamao n. Si el tamao es par invertir los elementos de la mitad de los elementosEjemplo:   v=[1][2][3][4][5][6]      v(invertido)=[3][2][1][6][5][4]*/Código:class JavaVectores1{    void llenar (int V [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.print (quot;
Inserte pos.[quot;
 + i + quot;
]: quot;
);    V [i] = Leer.datoInt ();}    }    void mostrar (int V [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.print (quot;
[quot;
 + V [i] + quot;
]quot;
);}    }    void invierte (int V [], int d)    {int aux1;int fin1 = d / 2;for (int i = 1 ; i <= (d / 2) / 2 ; i++){    aux1 = V [i];    V [i] = V [fin1];    V [fin1] = aux1;    fin1--;}fin1 = d;for (int j = (d / 2) + 1 ; j <= (d / 2) + 1 ; j++){    aux1 = V [j];    V [j] = V [fin1];    V [fin1] = aux1;    fin1--;}    }    public static void main (String args [])    {JavaVectores1 h = new JavaVectores1 ();int V [] = new int [20];System.out.print (quot;
Inserte dimen. del vector: quot;
);int d = Leer.datoInt ();h.llenar (V, d);System.out.println (quot;
VECTOR ORIGINAL: quot;
);h.mostrar (V, d);System.out.println (quot;
VECTOR LUEGO DE LA INVERSION: quot;
);h.invierte (V, d);h.mostrar (V, d);    }}/*Dado un polinomio evualuarlo en el punto x (todo en un vector)*/Código:class JavaVectores2{    void llenar (int V [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.print (quot;
Inserte pos.[quot;
 + i + quot;
]: quot;
);    V [i] = Leer.datoInt ();}    }    void mostrar (int V [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.print (quot;
[quot;
 + V [i] + quot;
]quot;
);}    }    int potencia (int b, int e)    {int p = 1;for (int i = 1 ; i <= e ; i++){    p = p * b;}return (p);    }    void evalua (int V [], int d, int x)    {int s = 0;for (int i = 1 ; i <= d ; i += 2){    s = s + (V [i] * potencia (x, V [i + 1]));}System.out.println (quot;
X es igual a: quot;
 + s);    }    public static void main (String args [])    {JavaVectores2 h = new JavaVectores2 ();int V [] = new int [20];System.out.print (quot;
Inserte dimen. del vector: quot;
);int d = Leer.datoInt ();System.out.print (quot;
Inserte valor de (x): quot;
);int x = Leer.datoInt ();h.llenar (V, d);System.out.println (quot;
VECTOR: quot;
);h.mostrar (V, d);h.evalua (V, d, x);    }}<br />>> MATRICES <</*Dadas dos matrices A y B intercambiar los minimos de A con los maximos de B*/Código:class JavaMatrices1{    void llenar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot;
Inserte pos[quot;
 + i + quot;
][quot;
 + j + quot;
]: quot;
);M [i] [j] = Leer.datoInt ();    }}    }    void mostrar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    System.out.println ();    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot;
[quot;
 + M [i] [j] + quot;
]quot;
);    }}    }    int menor (int M [] [], int f, int c)    {int men = M [1] [1];for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {if (M [i] [j] < men)    men = M [i] [j];    }}return (men);    }    int maximo (int M [] [], int f, int c)    {int max = M [1] [1];for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {if (M [i] [j] < max)    max = M [i] [j];    }}return (max);    }    void intercambiar (int A [] [], int fa, int ca, int B [] [], int fb, int cb)    {int min_a = menor (A, fa, ca);int max_b = maximo (B, fb, cb);//para cambiar los minimos de A con los maximos de Bfor (int i = 1 ; i <= fa ; i++){    for (int j = 1 ; j <= ca ; j++)    {if (A [i] [j] == min_a)    A [i] [j] = max_b;    }}//para intercambiar los maximos de con los minimos de Afor (int i = 1 ; i <= fb ; i++){    for (int j = 1 ; j <= cb ; j++)    {if (B [i] [j] == max_b)    B [i] [j] = min_a;    }}    }    public static void main (String args [])    {JavaMatrices1 h = new JavaMatrices1 ();int A [] [] = new int [20] [20];int B [] [] = new int [20] [20];System.out.print (quot;
Insert filas de A: quot;
);int fa = Leer.datoInt ();System.out.print (quot;
Insert columnas de A: quot;
);int ca = Leer.datoInt ();System.out.print (quot;
Insert filas de B: quot;
);int fb = Leer.datoInt ();System.out.print (quot;
Insert columnas de B: quot;
);int cb = Leer.datoInt ();//lectura de matricesSystem.out.println (quot;
INSERTANDO DATOS EN MATRIS A: quot;
);h.llenar (A, fa, ca);System.out.println (quot;
INSERTANDO DATOS EN MATRIS B: quot;
);h.llenar (B, fb, cb);System.out.println (quot;
MATRICES ORIGINALMENTE INSERTADAS: quot;
);h.mostrar (A, fa, ca);System.out.println ();h.mostrar (B, fb, cb);System.out.println ();//intercambiando elementosh.intercambiar (A, fa, ca, B, fb, cb);System.out.println (quot;
MATRICES DESPUES DEL INTERCAMBIO:quot;
);h.mostrar (A, fa, ca);System.out.println ();h.mostrar (B, fb, cb);    }}/*Dada una matris cuadrada invertir su diagonal principal*/Código:class JavaMatrices2{    void llenar (int M [] [], int d)    {for (int i = 1 ; i <= d ; i++){    for (int j = 1 ; j <= d ; j++)    {System.out.print (quot;
Inserte pos[quot;
 + i + quot;
][quot;
 + j + quot;
]: quot;
);M [i] [j] = Leer.datoInt ();    }}    }    void mostrar (int M [] [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.println ();    for (int j = 1 ; j <= d ; j++)    {System.out.print (quot;
[quot;
 + M [i] [j] + quot;
]quot;
);    }}    }    void invierte (int M [] [], int d)    {int fin = d;for (int i = 1 ; i <= d / 2 ; i++){    int aux = M [i] [i];    M [i] [i] = M [d] [d];    M [d] [d] = aux;    fin--;}    }    public static void main (String args [])    {JavaMatrices2 h = new JavaMatrices2 ();int M [] [] = new int [20] [20];System.out.print (quot;
Inserte dimen. de la matris cuadrada: quot;
);int d = Leer.datoInt ();h.llenar (M, d);System.out.print (quot;
MATRIS ORIGINAL: quot;
);h.mostrar (M, d);System.out.print (quot;
MATRIS CON LA DIAGONAL PRINCIPAL INVERTIDA: quot;
);h.invierte (M, d);h.mostrar (M, d);    }}/*Dada una matris cuadrada invertir su diagonal secundaria*/Código:class JavaMatrices3{    void llenar (int M [] [], int d)    {for (int i = 1 ; i <= d ; i++){    for (int j = 1 ; j <= d ; j++)    {System.out.print (quot;
Inserte pos[quot;
 + i + quot;
][quot;
 + j + quot;
]: quot;
);M [i] [j] = Leer.datoInt ();    }}    }    void mostrar (int M [] [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.println ();    for (int j = 1 ; j <= d ; j++)    {System.out.print (quot;
[quot;
 + M [i] [j] + quot;
]quot;
);    }}    }    void invierte (int M [] [], int d)    {int fin = d;for (int i = 1 ; i <= d / 2 ; i++){    int aux = M [i] [d];    M [i] [d] = M [d] [i];    M [d] [i] = aux;    fin--;}    }    public static void main (String args [])    {JavaMatrices3 h = new JavaMatrices3 ();int M [] [] = new int [20] [20];System.out.print (quot;
Inserte dimen. de la matris cuadrada: quot;
);int d = Leer.datoInt ();h.llenar (M, d);System.out.print (quot;
MATRIS ORIGINAL: quot;
);h.mostrar (M, d);System.out.print (quot;
MATRIS CON LA DIAGONAL SECUNDARIA INVERTIDA: quot;
);h.invierte (M, d);h.mostrar (M, d);    }}/*Dada dos matrices de diferentes tamanios R y S mostrar los elementos comunes de R en S*/Código:class JavaMatrices4{    void llenar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot;
Inserte pos[quot;
 + i + quot;
][quot;
 + j + quot;
]: quot;
);M [i] [j] = Leer.datoInt ();    }}    }    void mostrar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    System.out.println ();    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot;
[quot;
 + M [i] [j] + quot;
]quot;
);    }}    }    void comunes (int R [] [], int fr, int cr, int S [] [], int fs, int cs)    {System.out.print (quot;
Los elementos comunes de R en S son: quot;
);for (int i = 1 ; i <= fr ; i++){    for (int j = 1 ; j <= cr ; j++)    {for (int k = 1 ; k <= fs ; k++){    for (int l = 1 ; l <= cs ; l++)    {if (R [i] [j] == S [k] [l])    System.out.print (quot;
[quot;
 + R [i] [j] + quot;
]quot;
);    }}    }}    }    public static void main (String args [])    {JavaMatrices4 h = new JavaMatrices4 ();int R [] [] = new int [20] [20];int S [] [] = new int [20] [20];System.out.print (quot;
Inserte filas de R: quot;
);int fr = Leer.datoInt ();System.out.print (quot;
Inserte columnas de R: quot;
);int cr = Leer.datoInt ();System.out.print (quot;
Inserte filas de S: quot;
);int fs = Leer.datoInt ();System.out.print (quot;
Inserte columnas de S: quot;
);int cs = Leer.datoInt ();System.out.print (quot;
LLENANDO MATRIS R: quot;
);h.llenar (R, fr, cr);System.out.print (quot;
LLENANDO MATRIS S: quot;
);h.llenar (S, fs, cs);System.out.print (quot;
LA MATRICES R : quot;
);h.mostrar (R, fr, cr);System.out.print (quot;
LA MATRICES S : quot;
);h.mostrar (S, fs, cs);h.comunes (R, fr, cr, S, fs, cs);    }}/*Dada una matris intercambiar los elementos de la primera columna con la ultima columna*/Código:class JavaMatrices5{    void llenar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot;
Inserte pos[quot;
 + i + quot;
][quot;
 + j + quot;
]: quot;
);M [i] [j] = Leer.datoInt ();    }}    }    void mostrar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    System.out.println ();    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot;
[quot;
 + M [i] [j] + quot;
]quot;
);    }}    }    void intercambiar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    int aux = M [i] [1];    M [i] [1] = M [i] [c];    M [i] [c] = aux;}    }    public static void main (String args [])    {JavaMatrices5 h = new JavaMatrices5 ();int M [] [] = new int [20] [20];System.out.print (quot;
Inserte filas de la matris: quot;
);int f = Leer.datoInt ();System.out.print (quot;
Inserte columnas de la matris: quot;
);int c = Leer.datoInt ();System.out.print (quot;
LLENANDO MATRIS : quot;
);h.llenar (M, f, c);System.out.print (quot;
LA MATRIS ORIGINAL : quot;
);h.mostrar (M, f, c);System.out.print (quot;
LA MATRICES INTERCAMBIADA : quot;
);h.intercambiar (M, f, c);h.mostrar (M, f, c);    }}/* Contar el numero de digitos de cada elemento de una matris */Código:class JavaMatrices6{    void llenar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot;
Inserte pos[quot;
 + i + quot;
][quot;
 + j + quot;
]: quot;
);M [i] [j] = Leer.datoInt ();    }}    }    void mostrar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    System.out.println ();    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot;
[quot;
 + M [i] [j] + quot;
]quot;
);    }}    }    void cuenta (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot;
[quot;
 + M [i] [j] + quot;
] tiene: quot;
 + digitos (M [i] [j]) + quot;
 digito(s)quot;
);    }}    }    int digitos (int n)    {int contador = 0;while (n != 0){    n = n / 10;    contador++;}return (contador);    }    public static void main (String args [])    {JavaMatrices6 h = new JavaMatrices6 ();int M [] [] = new int [20] [20];System.out.print (quot;
Inserte filas de la matris: quot;
);int f = Leer.datoInt ();System.out.print (quot;
Inserte columnas de la matris: quot;
);int c = Leer.datoInt ();System.out.print (quot;
LLENANDO MATRIS M: quot;
);h.llenar (M, f, c);System.out.print (quot;
LA MATRIS: quot;
);h.mostrar (M, f, c);System.out.print (quot;
CONTEO DE DIGITOS: quot;
);h.cuenta (M, f, c);    }}<br />>> MATRICES Y VECTORES<</*Dada la matrix de m*n y el vector de tamanio n, determinar que columna de la matrises igual al vector*/Código:class JavaMatrisVector2{    void llenarMatris (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot;
Inserte pos[quot;
 + i + quot;
][quot;
 + j + quot;
]: quot;
);M [i] [j] = Leer.datoInt ();    }}    }    void mostrarMatris (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    System.out.println ();    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot;
[quot;
 + M [i] [j] + quot;
]quot;
);    }}    }    void llenarVector (int V [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.print (quot;
Inserte pos.[quot;
 + i + quot;
]: quot;
);    V [i] = Leer.datoInt ();}    }    void mostrarVector (int V [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.print (quot;
[quot;
 + V [i] + quot;
]quot;
);}    }    void procedure (int M [] [], int f, int c, int V [], int d)    {for (int i = 1 ; i <= f ; i++){    int sw = 1;    for (int j = 1 ; j <= c ; j++)    {for (int k = 1 ; k <= d ; k++){    if (M [j] [i] != V [k])sw = 0;}    }    if (sw == 1)System.out.println (quot;
La columna quot;
 + i + quot;
 es igual al vectorquot;
);}    }    public static void main (String args [])    {JavaMatrisVector2 h = new JavaMatrisVector2 ();int M [] [] = new int [20] [20];int V [] = new int [20];System.out.print (quot;
Inserte filas de la matris: quot;
);int f = Leer.datoInt ();System.out.print (quot;
Inserte dimension del vector: quot;
);int d = Leer.datoInt ();System.out.print (quot;
LLENANDO MATRIS: quot;
);h.llenarMatris (M, f, d);System.out.print (quot;
LLENANDO EL VECTOR: quot;
);h.llenarVector (V, d);System.out.print (quot;
LA MATRIS: quot;
);h.mostrarMatris (M, f, d);System.out.print (quot;
EL VECTOR: quot;
);h.mostrarVector (V, d);h.procedure (M, f, d, V, d);    }}/*Dada una matris Z almacenar en un vector A la suma por sus columnasy en un vector B la suma por sus filas*/Código:class JavaMatrisVector3{    void llenarMatris (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot;
Inserte pos[quot;
 + i + quot;
][quot;
 + j + quot;
]: quot;
);M [i] [j] = Leer.datoInt ();    }}    }    void mostrarMatris (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    System.out.println ();    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot;
[quot;
 + M [i] [j] + quot;
]quot;
);    }}    }    void mostrarVector (int V [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.print (quot;
[quot;
 + V [i] + quot;
]quot;
);}    }    void vectorA (int M [] [], int f, int c, int A [], int d)    {for (int i = 1 ; i <= f ; i++){    int suma = 0;    for (int j = 1 ; j <= c ; j++)    {suma = suma + M [j] [i];    }    A [i] = suma;}    }    void vectorB (int M [] [], int f, int c, int B [], int d)    {for (int i = 1 ; i <= f ; i++){    int suma = 0;    for (int j = 1 ; j <= c ; j++)    {suma = suma + M [i] [j];    }    B [i] = suma;}    }    public static void main (String args [])    {JavaMatrisVector3 h = new JavaMatrisVector3 ();int Z [] [] = new int [20] [20];int A [] = new int [20];int B [] = new int [20];System.out.print (quot;
Inserte filas de la matris: quot;
);int f = Leer.datoInt ();System.out.print (quot;
Inserte columnas de la matris: quot;
);int c = Leer.datoInt ();System.out.print (quot;
LLENANDO MATRIS: quot;
);h.llenarMatris (Z, f, c);System.out.print (quot;
LA MATRIZ Z: quot;
);h.mostrarMatris (Z, f, c);System.out.println (quot;
SUMA POR COLUMNAS DE LA MATRIS (vector A): quot;
);h.vectorA (Z, f, c, A, c);h.mostrarVector (A, c);System.out.println (quot;
SUMA POR FILAS DE LA MATRIS (vector B): quot;
);h.vectorB (Z, f, c, B, f);h.mostrarVector (B, f);    }}<br />Resolver los siguientes ejercicios:1. Crear un vector entero en donde almacene 10 número e imprimir dicho números.2. Crear un vector de tipo cadena que almacene 10 elementos e imprimir la palabra java seguido del número de elemento.3. Crear una aplicación que imprima la siguiente matriz.11   12   13   14   1521   22   23   24   2531   32   33   34   354.   Crear la siguiente matriz unidad, como se muestra la gráfica1.0   0.0   0.0   0.00.0   1.0   0.0   0.00.0   0.0   1.0   0.00.0   0.0   0.0   1.05. Crear una aplicación para buscar un número en una matriz, e imprimir la ubicación de dicho número.6. Crear una aplicación que busque el número más grande del array y (a posición que ocupa.7. Crear un vector para cargar 5 numero, e imprimir el mayor, menor, medio y la lista ordenada de menor a mayor<br />
Ejercicios resueltos de java
Ejercicios resueltos de java
Ejercicios resueltos de java
Ejercicios resueltos de java
Ejercicios resueltos de java
Ejercicios resueltos de java
Ejercicios resueltos de java
Ejercicios resueltos de java
Ejercicios resueltos de java
Ejercicios resueltos de java
Ejercicios resueltos de java
Ejercicios resueltos de java
Ejercicios resueltos de java
Ejercicios resueltos de java
Ejercicios resueltos de java
Ejercicios resueltos de java

Contenu connexe

Tendances

Bucles de Control Repetitivo Ciclos For
Bucles de Control Repetitivo  Ciclos ForBucles de Control Repetitivo  Ciclos For
Bucles de Control Repetitivo Ciclos ForRichard Robalino
 
Python dictionary
Python dictionaryPython dictionary
Python dictionaryeman lotfy
 
Resolución de problemas con java
Resolución de problemas con javaResolución de problemas con java
Resolución de problemas con javadiegocastro1234
 
[APJ] Common Table Expressions (CTEs) in SQL
[APJ] Common Table Expressions (CTEs) in SQL[APJ] Common Table Expressions (CTEs) in SQL
[APJ] Common Table Expressions (CTEs) in SQLEDB
 
Oracle Spatial de la A a la Z - Unidad 10
Oracle Spatial de la A a la Z - Unidad 10Oracle Spatial de la A a la Z - Unidad 10
Oracle Spatial de la A a la Z - Unidad 10Jorge Ulises
 
Fundamentos de Programacion - Unidad 5 arreglos (vectores)
Fundamentos de Programacion - Unidad 5 arreglos (vectores)Fundamentos de Programacion - Unidad 5 arreglos (vectores)
Fundamentos de Programacion - Unidad 5 arreglos (vectores)José Antonio Sandoval Acosta
 
Tipos de metodos programacion dos
Tipos de metodos  programacion dosTipos de metodos  programacion dos
Tipos de metodos programacion dosEdesTigse
 
SQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredSQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredDanish Mehraj
 
Programa en C++ ( escriba 3 números y diga cual es el mayor))
Programa en C++ ( escriba 3 números y diga cual es el mayor))Programa en C++ ( escriba 3 números y diga cual es el mayor))
Programa en C++ ( escriba 3 números y diga cual es el mayor))Alex Penso Romero
 
Metodos de programacion
Metodos de programacionMetodos de programacion
Metodos de programacionadvmct
 
Java pilas (Stacks) y colas (Queues)
Java pilas (Stacks) y colas (Queues)Java pilas (Stacks) y colas (Queues)
Java pilas (Stacks) y colas (Queues)Juan Astudillo
 

Tendances (20)

4 Introducción al lenguaje Scala
4 Introducción al lenguaje Scala4 Introducción al lenguaje Scala
4 Introducción al lenguaje Scala
 
Algoritmos para c#
Algoritmos para c#Algoritmos para c#
Algoritmos para c#
 
Bucles de Control Repetitivo Ciclos For
Bucles de Control Repetitivo  Ciclos ForBucles de Control Repetitivo  Ciclos For
Bucles de Control Repetitivo Ciclos For
 
Matrices pseint
Matrices   pseintMatrices   pseint
Matrices pseint
 
JUnit 4
JUnit 4JUnit 4
JUnit 4
 
Python dictionary
Python dictionaryPython dictionary
Python dictionary
 
Resolución de problemas con java
Resolución de problemas con javaResolución de problemas con java
Resolución de problemas con java
 
[APJ] Common Table Expressions (CTEs) in SQL
[APJ] Common Table Expressions (CTEs) in SQL[APJ] Common Table Expressions (CTEs) in SQL
[APJ] Common Table Expressions (CTEs) in SQL
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Oracle Spatial de la A a la Z - Unidad 10
Oracle Spatial de la A a la Z - Unidad 10Oracle Spatial de la A a la Z - Unidad 10
Oracle Spatial de la A a la Z - Unidad 10
 
Fundamentos de Programacion - Unidad 5 arreglos (vectores)
Fundamentos de Programacion - Unidad 5 arreglos (vectores)Fundamentos de Programacion - Unidad 5 arreglos (vectores)
Fundamentos de Programacion - Unidad 5 arreglos (vectores)
 
Tipos de metodos programacion dos
Tipos de metodos  programacion dosTipos de metodos  programacion dos
Tipos de metodos programacion dos
 
SQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredSQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics Covered
 
Programa en C++ ( escriba 3 números y diga cual es el mayor))
Programa en C++ ( escriba 3 números y diga cual es el mayor))Programa en C++ ( escriba 3 números y diga cual es el mayor))
Programa en C++ ( escriba 3 números y diga cual es el mayor))
 
Clean code
Clean code Clean code
Clean code
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
Metodos de programacion
Metodos de programacionMetodos de programacion
Metodos de programacion
 
Java pilas (Stacks) y colas (Queues)
Java pilas (Stacks) y colas (Queues)Java pilas (Stacks) y colas (Queues)
Java pilas (Stacks) y colas (Queues)
 

En vedette

Ejercicios de evaluación de fundametnos de programacion en JAva
Ejercicios de evaluación de fundametnos de programacion en JAvaEjercicios de evaluación de fundametnos de programacion en JAva
Ejercicios de evaluación de fundametnos de programacion en JAvaMartha Beatriz Coronado Rosales
 
Ejercicios en Netbeans
Ejercicios en NetbeansEjercicios en Netbeans
Ejercicios en Netbeansedgar muñoz
 
Proyecto plan padrino "Buscando una Sonrisa Chigorodoseñita para esta Navidad...
Proyecto plan padrino "Buscando una Sonrisa Chigorodoseñita para esta Navidad...Proyecto plan padrino "Buscando una Sonrisa Chigorodoseñita para esta Navidad...
Proyecto plan padrino "Buscando una Sonrisa Chigorodoseñita para esta Navidad...Andres Chavarro
 
Navidad 2013-oficio donación de juguetes e
Navidad 2013-oficio donación de juguetes eNavidad 2013-oficio donación de juguetes e
Navidad 2013-oficio donación de juguetes eyoteamomucho
 

En vedette (7)

Unidad 3: Herencia Ejercicio 3
Unidad 3: Herencia Ejercicio 3Unidad 3: Herencia Ejercicio 3
Unidad 3: Herencia Ejercicio 3
 
Ejercicios de evaluación de fundametnos de programacion en JAva
Ejercicios de evaluación de fundametnos de programacion en JAvaEjercicios de evaluación de fundametnos de programacion en JAva
Ejercicios de evaluación de fundametnos de programacion en JAva
 
Ejercicios en Netbeans
Ejercicios en NetbeansEjercicios en Netbeans
Ejercicios en Netbeans
 
Proyecto plan padrino "Buscando una Sonrisa Chigorodoseñita para esta Navidad...
Proyecto plan padrino "Buscando una Sonrisa Chigorodoseñita para esta Navidad...Proyecto plan padrino "Buscando una Sonrisa Chigorodoseñita para esta Navidad...
Proyecto plan padrino "Buscando una Sonrisa Chigorodoseñita para esta Navidad...
 
Soluc libro mate 2009
Soluc libro mate 2009Soluc libro mate 2009
Soluc libro mate 2009
 
Navidad 2013-oficio donación de juguetes e
Navidad 2013-oficio donación de juguetes eNavidad 2013-oficio donación de juguetes e
Navidad 2013-oficio donación de juguetes e
 
modelo de oficios para Donaciones
modelo de oficios para Donacionesmodelo de oficios para Donaciones
modelo de oficios para Donaciones
 

Ejercicios resueltos de java

  • 1. EJERCICIOS RESUELTOS DE JAVA>> ARITMETICA <<- Hallar A+B-C+100Código:class JavaAritmetica1{    public static void main (String mago [])    {int A, B, C;System.out.print (quot; Inserte A: quot; );A = Leer.datoInt ();System.out.print (quot; Inserte B: quot; );B = Leer.datoInt ();System.out.print (quot; Inserte C: quot; );C = Leer.datoInt ();System.out.println (quot; quot; + A + quot; + quot; + quot; quot; + B + quot; - quot; + C + quot; + quot; + 100 + quot; = quot; + (A + B - C + 100));    }}Hallar (a-b)(a+b)Código:class JavaAritmetica2{    public static void main (String elMago [])    {int a, b;System.out.print (quot; Inserte valor a: quot; );a = Leer.datoInt ();System.out.print (quot; Inserte valor b: quot; );b = Leer.datoInt ();System.out.println (quot; (quot; + a + quot; -quot; + b + quot; ) quot; + quot; (quot; + a + quot; +quot; + b + quot; ) quot; + quot; = quot; + ((a - b) * (a + b)));    }}Leer un numeo de tres digitos y sumarlosCódigo:class JavaAritmetica3{    public static void main (String elMago [])    {int numero, sumDig = 0;System.out.print (quot; Inserte numero de tres digitos: quot; );numero = Leer.datoInt ();if (numero <= 100)    System.out.println (quot; ERROR: El numero no tiene 3 digitosquot; );else{    int aux = numero; //en aux salvamos numero    while (numero != 0)    {sumDig = sumDig + (numero % 10); //sumamos a sumDig el ultimo digito de numeronumero = numero / 10; //eliminamos el ultimo digito de numero    }    System.out.println (quot; La suma de los digitos de quot; + aux + quot; es: quot; + sumDig);}    }}Dado un numero verificar:    - Que tenga dos digitos    - Verificar si sus digitos son pares    - Promediar sus digitos Código:class JavaAritmetica4{    public static void main (String args [])    {int numero;System.out.print (quot; Inserte un numero de dos digitos pares: quot; );numero = Leer.datoInt ();int aux = numero;if (numero < 100 && numero > 9){    int d1 = numero % 10;    numero = numero / 10;    int d2 = numero % 10;    if (d1 % 2 == 0 && d2 % 2 == 0)System.out.println (quot; El promedio de los digitos de: quot; + aux + quot; es: quot; + ((d1 + d2) / 2));}    }}Dado un numero entero, determinar si es positivo, negativo o nuloCódigo:class JavaAritmetica5{    public static void main (String args [])    {int numero;System.out.print (quot; Inserte un numero: quot; );numero = Leer.datoInt ();if (numero == 0)    System.out.println (quot; El numero quot; + numero + quot; es NULOquot; );else{    if (numero < 0)System.out.println (quot; El numero quot; + numero + quot; es NEGATIVOquot; );    elseSystem.out.println (quot; El numero quot; + numero + quot; es POSITIVOquot; );}    }}Dados seis numero determinar el menor de ellosCódigo:class JavaAritmetica6{    public static void main (String args [])    {int a, b, c, d, e, f;System.out.print (quot; Inserte num.1: quot; );a = Leer.datoInt ();System.out.print (quot; Inserte num.2: quot; );b = Leer.datoInt ();System.out.print (quot; Inserte num.3: quot; );c = Leer.datoInt ();System.out.print (quot; Inserte num.4: quot; );d = Leer.datoInt ();System.out.print (quot; Inserte num.5: quot; );e = Leer.datoInt ();System.out.print (quot; Inserte num.6: quot; );f = Leer.datoInt ();int menor = a;if (b < menor)    menor = b;if (c < menor)    menor = c;if (d < menor)    menor = d;if (e < menor)    menor = e;if (f < menor)    menor = f;System.out.println (quot; El menor de:quot; + a + quot; ,quot; + b + quot; ,quot; + c + quot; ,quot; + d + quot; ,quot; + e + quot; ,quot; + f + quot; ,quot; );System.out.println (quot; Es: quot; + menor);    }}<br />>> SERIES <<Generar 5,10,15,20,25,30,...Código:class JavaSeries1{    public static void main (String args [])    {int n, c = 1, serie = 5;System.out.print (quot; Cantidad d terminos: quot; );n = Leer.datoInt ();while (c <= n){    System.out.print (quot; ,quot; + serie);    serie += 5;    c++;}    }}Si n=7  generar 7,6,5,4,3,2,1    Código:class JavaSeries2{    public static void main (String args [])    {int n, c = 1;System.out.print (quot; Cantidad d terminos: quot; );n = Leer.datoInt ();int serie = n;while (c <= n){    System.out.print (serie + quot; ,quot; );    serie--;    c++;}    }}<br />>> VECTORES <</*Dado el vector T de tamao n. Si el tamao es par invertir los elementos de la mitad de los elementosEjemplo:   v=[1][2][3][4][5][6]      v(invertido)=[3][2][1][6][5][4]*/Código:class JavaVectores1{    void llenar (int V [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.print (quot; Inserte pos.[quot; + i + quot; ]: quot; );    V [i] = Leer.datoInt ();}    }    void mostrar (int V [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.print (quot; [quot; + V [i] + quot; ]quot; );}    }    void invierte (int V [], int d)    {int aux1;int fin1 = d / 2;for (int i = 1 ; i <= (d / 2) / 2 ; i++){    aux1 = V [i];    V [i] = V [fin1];    V [fin1] = aux1;    fin1--;}fin1 = d;for (int j = (d / 2) + 1 ; j <= (d / 2) + 1 ; j++){    aux1 = V [j];    V [j] = V [fin1];    V [fin1] = aux1;    fin1--;}    }    public static void main (String args [])    {JavaVectores1 h = new JavaVectores1 ();int V [] = new int [20];System.out.print (quot; Inserte dimen. del vector: quot; );int d = Leer.datoInt ();h.llenar (V, d);System.out.println (quot; VECTOR ORIGINAL: quot; );h.mostrar (V, d);System.out.println (quot; VECTOR LUEGO DE LA INVERSION: quot; );h.invierte (V, d);h.mostrar (V, d);    }}/*Dado un polinomio evualuarlo en el punto x (todo en un vector)*/Código:class JavaVectores2{    void llenar (int V [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.print (quot; Inserte pos.[quot; + i + quot; ]: quot; );    V [i] = Leer.datoInt ();}    }    void mostrar (int V [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.print (quot; [quot; + V [i] + quot; ]quot; );}    }    int potencia (int b, int e)    {int p = 1;for (int i = 1 ; i <= e ; i++){    p = p * b;}return (p);    }    void evalua (int V [], int d, int x)    {int s = 0;for (int i = 1 ; i <= d ; i += 2){    s = s + (V [i] * potencia (x, V [i + 1]));}System.out.println (quot; X es igual a: quot; + s);    }    public static void main (String args [])    {JavaVectores2 h = new JavaVectores2 ();int V [] = new int [20];System.out.print (quot; Inserte dimen. del vector: quot; );int d = Leer.datoInt ();System.out.print (quot; Inserte valor de (x): quot; );int x = Leer.datoInt ();h.llenar (V, d);System.out.println (quot; VECTOR: quot; );h.mostrar (V, d);h.evalua (V, d, x);    }}<br />>> MATRICES <</*Dadas dos matrices A y B intercambiar los minimos de A con los maximos de B*/Código:class JavaMatrices1{    void llenar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot; Inserte pos[quot; + i + quot; ][quot; + j + quot; ]: quot; );M [i] [j] = Leer.datoInt ();    }}    }    void mostrar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    System.out.println ();    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot; [quot; + M [i] [j] + quot; ]quot; );    }}    }    int menor (int M [] [], int f, int c)    {int men = M [1] [1];for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {if (M [i] [j] < men)    men = M [i] [j];    }}return (men);    }    int maximo (int M [] [], int f, int c)    {int max = M [1] [1];for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {if (M [i] [j] < max)    max = M [i] [j];    }}return (max);    }    void intercambiar (int A [] [], int fa, int ca, int B [] [], int fb, int cb)    {int min_a = menor (A, fa, ca);int max_b = maximo (B, fb, cb);//para cambiar los minimos de A con los maximos de Bfor (int i = 1 ; i <= fa ; i++){    for (int j = 1 ; j <= ca ; j++)    {if (A [i] [j] == min_a)    A [i] [j] = max_b;    }}//para intercambiar los maximos de con los minimos de Afor (int i = 1 ; i <= fb ; i++){    for (int j = 1 ; j <= cb ; j++)    {if (B [i] [j] == max_b)    B [i] [j] = min_a;    }}    }    public static void main (String args [])    {JavaMatrices1 h = new JavaMatrices1 ();int A [] [] = new int [20] [20];int B [] [] = new int [20] [20];System.out.print (quot; Insert filas de A: quot; );int fa = Leer.datoInt ();System.out.print (quot; Insert columnas de A: quot; );int ca = Leer.datoInt ();System.out.print (quot; Insert filas de B: quot; );int fb = Leer.datoInt ();System.out.print (quot; Insert columnas de B: quot; );int cb = Leer.datoInt ();//lectura de matricesSystem.out.println (quot; INSERTANDO DATOS EN MATRIS A: quot; );h.llenar (A, fa, ca);System.out.println (quot; INSERTANDO DATOS EN MATRIS B: quot; );h.llenar (B, fb, cb);System.out.println (quot; MATRICES ORIGINALMENTE INSERTADAS: quot; );h.mostrar (A, fa, ca);System.out.println ();h.mostrar (B, fb, cb);System.out.println ();//intercambiando elementosh.intercambiar (A, fa, ca, B, fb, cb);System.out.println (quot; MATRICES DESPUES DEL INTERCAMBIO:quot; );h.mostrar (A, fa, ca);System.out.println ();h.mostrar (B, fb, cb);    }}/*Dada una matris cuadrada invertir su diagonal principal*/Código:class JavaMatrices2{    void llenar (int M [] [], int d)    {for (int i = 1 ; i <= d ; i++){    for (int j = 1 ; j <= d ; j++)    {System.out.print (quot; Inserte pos[quot; + i + quot; ][quot; + j + quot; ]: quot; );M [i] [j] = Leer.datoInt ();    }}    }    void mostrar (int M [] [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.println ();    for (int j = 1 ; j <= d ; j++)    {System.out.print (quot; [quot; + M [i] [j] + quot; ]quot; );    }}    }    void invierte (int M [] [], int d)    {int fin = d;for (int i = 1 ; i <= d / 2 ; i++){    int aux = M [i] [i];    M [i] [i] = M [d] [d];    M [d] [d] = aux;    fin--;}    }    public static void main (String args [])    {JavaMatrices2 h = new JavaMatrices2 ();int M [] [] = new int [20] [20];System.out.print (quot; Inserte dimen. de la matris cuadrada: quot; );int d = Leer.datoInt ();h.llenar (M, d);System.out.print (quot; MATRIS ORIGINAL: quot; );h.mostrar (M, d);System.out.print (quot; MATRIS CON LA DIAGONAL PRINCIPAL INVERTIDA: quot; );h.invierte (M, d);h.mostrar (M, d);    }}/*Dada una matris cuadrada invertir su diagonal secundaria*/Código:class JavaMatrices3{    void llenar (int M [] [], int d)    {for (int i = 1 ; i <= d ; i++){    for (int j = 1 ; j <= d ; j++)    {System.out.print (quot; Inserte pos[quot; + i + quot; ][quot; + j + quot; ]: quot; );M [i] [j] = Leer.datoInt ();    }}    }    void mostrar (int M [] [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.println ();    for (int j = 1 ; j <= d ; j++)    {System.out.print (quot; [quot; + M [i] [j] + quot; ]quot; );    }}    }    void invierte (int M [] [], int d)    {int fin = d;for (int i = 1 ; i <= d / 2 ; i++){    int aux = M [i] [d];    M [i] [d] = M [d] [i];    M [d] [i] = aux;    fin--;}    }    public static void main (String args [])    {JavaMatrices3 h = new JavaMatrices3 ();int M [] [] = new int [20] [20];System.out.print (quot; Inserte dimen. de la matris cuadrada: quot; );int d = Leer.datoInt ();h.llenar (M, d);System.out.print (quot; MATRIS ORIGINAL: quot; );h.mostrar (M, d);System.out.print (quot; MATRIS CON LA DIAGONAL SECUNDARIA INVERTIDA: quot; );h.invierte (M, d);h.mostrar (M, d);    }}/*Dada dos matrices de diferentes tamanios R y S mostrar los elementos comunes de R en S*/Código:class JavaMatrices4{    void llenar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot; Inserte pos[quot; + i + quot; ][quot; + j + quot; ]: quot; );M [i] [j] = Leer.datoInt ();    }}    }    void mostrar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    System.out.println ();    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot; [quot; + M [i] [j] + quot; ]quot; );    }}    }    void comunes (int R [] [], int fr, int cr, int S [] [], int fs, int cs)    {System.out.print (quot; Los elementos comunes de R en S son: quot; );for (int i = 1 ; i <= fr ; i++){    for (int j = 1 ; j <= cr ; j++)    {for (int k = 1 ; k <= fs ; k++){    for (int l = 1 ; l <= cs ; l++)    {if (R [i] [j] == S [k] [l])    System.out.print (quot; [quot; + R [i] [j] + quot; ]quot; );    }}    }}    }    public static void main (String args [])    {JavaMatrices4 h = new JavaMatrices4 ();int R [] [] = new int [20] [20];int S [] [] = new int [20] [20];System.out.print (quot; Inserte filas de R: quot; );int fr = Leer.datoInt ();System.out.print (quot; Inserte columnas de R: quot; );int cr = Leer.datoInt ();System.out.print (quot; Inserte filas de S: quot; );int fs = Leer.datoInt ();System.out.print (quot; Inserte columnas de S: quot; );int cs = Leer.datoInt ();System.out.print (quot; LLENANDO MATRIS R: quot; );h.llenar (R, fr, cr);System.out.print (quot; LLENANDO MATRIS S: quot; );h.llenar (S, fs, cs);System.out.print (quot; LA MATRICES R : quot; );h.mostrar (R, fr, cr);System.out.print (quot; LA MATRICES S : quot; );h.mostrar (S, fs, cs);h.comunes (R, fr, cr, S, fs, cs);    }}/*Dada una matris intercambiar los elementos de la primera columna con la ultima columna*/Código:class JavaMatrices5{    void llenar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot; Inserte pos[quot; + i + quot; ][quot; + j + quot; ]: quot; );M [i] [j] = Leer.datoInt ();    }}    }    void mostrar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    System.out.println ();    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot; [quot; + M [i] [j] + quot; ]quot; );    }}    }    void intercambiar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    int aux = M [i] [1];    M [i] [1] = M [i] [c];    M [i] [c] = aux;}    }    public static void main (String args [])    {JavaMatrices5 h = new JavaMatrices5 ();int M [] [] = new int [20] [20];System.out.print (quot; Inserte filas de la matris: quot; );int f = Leer.datoInt ();System.out.print (quot; Inserte columnas de la matris: quot; );int c = Leer.datoInt ();System.out.print (quot; LLENANDO MATRIS : quot; );h.llenar (M, f, c);System.out.print (quot; LA MATRIS ORIGINAL : quot; );h.mostrar (M, f, c);System.out.print (quot; LA MATRICES INTERCAMBIADA : quot; );h.intercambiar (M, f, c);h.mostrar (M, f, c);    }}/* Contar el numero de digitos de cada elemento de una matris */Código:class JavaMatrices6{    void llenar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot; Inserte pos[quot; + i + quot; ][quot; + j + quot; ]: quot; );M [i] [j] = Leer.datoInt ();    }}    }    void mostrar (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    System.out.println ();    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot; [quot; + M [i] [j] + quot; ]quot; );    }}    }    void cuenta (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot; [quot; + M [i] [j] + quot; ] tiene: quot; + digitos (M [i] [j]) + quot; digito(s)quot; );    }}    }    int digitos (int n)    {int contador = 0;while (n != 0){    n = n / 10;    contador++;}return (contador);    }    public static void main (String args [])    {JavaMatrices6 h = new JavaMatrices6 ();int M [] [] = new int [20] [20];System.out.print (quot; Inserte filas de la matris: quot; );int f = Leer.datoInt ();System.out.print (quot; Inserte columnas de la matris: quot; );int c = Leer.datoInt ();System.out.print (quot; LLENANDO MATRIS M: quot; );h.llenar (M, f, c);System.out.print (quot; LA MATRIS: quot; );h.mostrar (M, f, c);System.out.print (quot; CONTEO DE DIGITOS: quot; );h.cuenta (M, f, c);    }}<br />>> MATRICES Y VECTORES<</*Dada la matrix de m*n y el vector de tamanio n, determinar que columna de la matrises igual al vector*/Código:class JavaMatrisVector2{    void llenarMatris (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot; Inserte pos[quot; + i + quot; ][quot; + j + quot; ]: quot; );M [i] [j] = Leer.datoInt ();    }}    }    void mostrarMatris (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    System.out.println ();    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot; [quot; + M [i] [j] + quot; ]quot; );    }}    }    void llenarVector (int V [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.print (quot; Inserte pos.[quot; + i + quot; ]: quot; );    V [i] = Leer.datoInt ();}    }    void mostrarVector (int V [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.print (quot; [quot; + V [i] + quot; ]quot; );}    }    void procedure (int M [] [], int f, int c, int V [], int d)    {for (int i = 1 ; i <= f ; i++){    int sw = 1;    for (int j = 1 ; j <= c ; j++)    {for (int k = 1 ; k <= d ; k++){    if (M [j] [i] != V [k])sw = 0;}    }    if (sw == 1)System.out.println (quot; La columna quot; + i + quot; es igual al vectorquot; );}    }    public static void main (String args [])    {JavaMatrisVector2 h = new JavaMatrisVector2 ();int M [] [] = new int [20] [20];int V [] = new int [20];System.out.print (quot; Inserte filas de la matris: quot; );int f = Leer.datoInt ();System.out.print (quot; Inserte dimension del vector: quot; );int d = Leer.datoInt ();System.out.print (quot; LLENANDO MATRIS: quot; );h.llenarMatris (M, f, d);System.out.print (quot; LLENANDO EL VECTOR: quot; );h.llenarVector (V, d);System.out.print (quot; LA MATRIS: quot; );h.mostrarMatris (M, f, d);System.out.print (quot; EL VECTOR: quot; );h.mostrarVector (V, d);h.procedure (M, f, d, V, d);    }}/*Dada una matris Z almacenar en un vector A la suma por sus columnasy en un vector B la suma por sus filas*/Código:class JavaMatrisVector3{    void llenarMatris (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot; Inserte pos[quot; + i + quot; ][quot; + j + quot; ]: quot; );M [i] [j] = Leer.datoInt ();    }}    }    void mostrarMatris (int M [] [], int f, int c)    {for (int i = 1 ; i <= f ; i++){    System.out.println ();    for (int j = 1 ; j <= c ; j++)    {System.out.print (quot; [quot; + M [i] [j] + quot; ]quot; );    }}    }    void mostrarVector (int V [], int d)    {for (int i = 1 ; i <= d ; i++){    System.out.print (quot; [quot; + V [i] + quot; ]quot; );}    }    void vectorA (int M [] [], int f, int c, int A [], int d)    {for (int i = 1 ; i <= f ; i++){    int suma = 0;    for (int j = 1 ; j <= c ; j++)    {suma = suma + M [j] [i];    }    A [i] = suma;}    }    void vectorB (int M [] [], int f, int c, int B [], int d)    {for (int i = 1 ; i <= f ; i++){    int suma = 0;    for (int j = 1 ; j <= c ; j++)    {suma = suma + M [i] [j];    }    B [i] = suma;}    }    public static void main (String args [])    {JavaMatrisVector3 h = new JavaMatrisVector3 ();int Z [] [] = new int [20] [20];int A [] = new int [20];int B [] = new int [20];System.out.print (quot; Inserte filas de la matris: quot; );int f = Leer.datoInt ();System.out.print (quot; Inserte columnas de la matris: quot; );int c = Leer.datoInt ();System.out.print (quot; LLENANDO MATRIS: quot; );h.llenarMatris (Z, f, c);System.out.print (quot; LA MATRIZ Z: quot; );h.mostrarMatris (Z, f, c);System.out.println (quot; SUMA POR COLUMNAS DE LA MATRIS (vector A): quot; );h.vectorA (Z, f, c, A, c);h.mostrarVector (A, c);System.out.println (quot; SUMA POR FILAS DE LA MATRIS (vector B): quot; );h.vectorB (Z, f, c, B, f);h.mostrarVector (B, f);    }}<br />Resolver los siguientes ejercicios:1. Crear un vector entero en donde almacene 10 número e imprimir dicho números.2. Crear un vector de tipo cadena que almacene 10 elementos e imprimir la palabra java seguido del número de elemento.3. Crear una aplicación que imprima la siguiente matriz.11   12   13   14   1521   22   23   24   2531   32   33   34   354.   Crear la siguiente matriz unidad, como se muestra la gráfica1.0   0.0   0.0   0.00.0   1.0   0.0   0.00.0   0.0   1.0   0.00.0   0.0   0.0   1.05. Crear una aplicación para buscar un número en una matriz, e imprimir la ubicación de dicho número.6. Crear una aplicación que busque el número más grande del array y (a posición que ocupa.7. Crear un vector para cargar 5 numero, e imprimir el mayor, menor, medio y la lista ordenada de menor a mayor<br />