Professional Documents
Culture Documents
Ejerciciosresueltosdejava 100823123543 Phpapp02
Ejerciciosresueltosdejava 100823123543 Phpapp02
- Hallar A+B-C+100
Código:
class JavaAritmetica1
{
public static void main (String mago [])
{
int A, B, C;
System.out.print ("Inserte A: ");
A = Leer.datoInt ();
System.out.print ("Inserte B: ");
B = Leer.datoInt ();
System.out.print ("Inserte C: ");
C = Leer.datoInt ();
System.out.println ("\n" + A + " + " + " " + B + " - " + C + " + " + 100 + " = " +
(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 ("Inserte valor a: ");
a = Leer.datoInt ();
System.out.print ("Inserte valor b: ");
b = Leer.datoInt ();
System.out.println ("(" + a + "-" + b + ") " + "(" + a + "+" + b + ") " + "= " + ((a
- b) * (a + b)));
}
}
}
}
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 ("Cantidad d terminos: ");
n = Leer.datoInt ();
while (c <= n)
{
System.out.print ("," + serie);
serie += 5;
c++;
}
}
}
/*Dado el vector T de tamao n. Si el tamao es par invertir los elementos de la mitad de los elementos
Ejemplo: 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 ("Inserte pos.[" + i + "]: ");
V [i] = Leer.datoInt ();
}
}
fin1 = d;
for (int j = (d / 2) + 1 ; j <= (d / 2) + 1 ; j++)
{
aux1 = V [j];
V [j] = V [fin1];
V [fin1] = aux1;
fin1--;
}
}
/*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 ("Inserte pos[" + i + "][" + j + "]: ");
M [i] [j] = Leer.datoInt ();
}
}
}
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);
//lectura de matrices
System.out.println ("\nINSERTANDO DATOS EN MATRIS A: \n");
h.llenar (A, fa, ca);
System.out.println ("\nINSERTANDO DATOS EN MATRIS B: \n");
h.llenar (B, fb, cb);
System.out.println ("\nMATRICES ORIGINALMENTE INSERTADAS: ");
h.mostrar (A, fa, ca);
System.out.println ();
h.mostrar (B, fb, cb);
System.out.println ();
//intercambiando elementos
h.intercambiar (A, fa, ca, B, fb, cb);
System.out.println ("\nMATRICES DESPUES DEL INTERCAMBIO:");
h.mostrar (A, fa, ca);
System.out.println ();
h.mostrar (B, fb, cb);
}
}
void comunes (int R [] [], int fr, int cr, int S [] [], int fs, int cs)
{
System.out.print ("\n\nLos elementos comunes de R en S son: ");
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 ("[" + R [i] [j] + "]");
}
}
}
}
}
/*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 ("Inserte pos[" + i + "][" + j + "]: ");
M [i] [j] = Leer.datoInt ();
}
}
}
2. Crear un vector de tipo cadena que almacene 10 elementos e imprimir la palabra java seguido del número de elemento.
5. 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