ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Ejercicios Resueltos De Java


Enviado por   •  19 de Agosto de 2013  •  4.436 Palabras (18 Páginas)  •  690 Visitas

Página 1 de 18

EJERCICIOS RESUELTOS DE JAVA

________________________________________

>> ARITMETICA <<

- 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)));

}

}

Leer un numeo de tres digitos y sumarlos

Código:

class JavaAritmetica3

{

public static void main (String elMago [])

{

int numero, sumDig = 0;

System.out.print ("Inserte numero de tres digitos: ");

numero = Leer.datoInt ();

if (numero <= 100)

System.out.println ("ERROR: El numero no tiene 3 digitos");

else

{

int aux = numero; //en aux salvamos numero

while (numero != 0)

{

sumDig = sumDig + (numero % 10); //sumamos a sumDig el ultimo digito de numero

numero = numero / 10; //eliminamos el ultimo digito de numero

}

System.out.println ("La suma de los digitos de " + aux + " es: " + 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 ("Inserte un numero de dos digitos pares: ");

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 ("El promedio de los digitos de: " + aux + " es: " + ((d1 + d2) / 2));

}

}

}

Dado un numero entero, determinar si es positivo, negativo o nulo

Código:

class JavaAritmetica5

{

public static void main (String args [])

{

int numero;

System.out.print ("Inserte un numero: ");

numero = Leer.datoInt ();

if (numero == 0)

System.out.println ("El numero " + numero + " es NULO");

else

{

if (numero < 0)

System.out.println ("El numero " + numero + " es NEGATIVO");

else

System.out.println ("El numero " + numero + " es POSITIVO");

}

}

}

Dados seis numero determinar el menor de ellos

Código:

class JavaAritmetica6

{

public static void main (String args [])

{

int a, b, c, d, e, f;

System.out.print ("Inserte num.1: ");

a = Leer.datoInt ();

System.out.print ("Inserte num.2: ");

b = Leer.datoInt ();

System.out.print ("Inserte num.3: ");

c = Leer.datoInt ();

System.out.print ("Inserte num.4: ");

d = Leer.datoInt ();

System.out.print ("Inserte num.5: ");

e = Leer.datoInt ();

System.out.print ("Inserte num.6: ");

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 ("\nEl menor de:" + a + "," + b + "," + c + "," + d + "," + e + "," + f + ",");

System.out.println ("Es: " + menor);

}

}

________________________________________

>> 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 ("Cantidad d terminos: ");

n = Leer.datoInt ();

while (c <= n)

{

System.out.print ("," + 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 ("Cantidad d terminos: ");

n = Leer.datoInt ();

int serie = n;

while (c <= n)

{

System.out.print (serie + ",");

serie--;

c++;

}

}

}

________________________________________

>> VECTORES <<

/*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 ();

}

}

void mostrar (int V [], int d)

{

...

Descargar como (para miembros actualizados)  txt (21 Kb)  
Leer 17 páginas más »
Disponible sólo en Clubensayos.com