Gdfgdf
- 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)));
}
}
Leerun 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:classJavaAritmetica4
{
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 promediode 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 ellosCó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);
}
}
|
|
| En línea |
[www.darvein.net] |
|
Darvein
Desconectado
Mensajes: 181
=)
| | Re: Ejercicios resueltos JAVA [programacion estructurada] «Respuesta #1 en: 26 Febrero 2008, 18:41 » | |
>> 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...
Regístrate para leer el documento completo.