Escolar Documentos
Profissional Documentos
Cultura Documentos
- Hallar A+B-C+100
Cdigo:
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)
Cdigo:
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
Cdigo:
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
Cdigo:
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
Cdigo:
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");
}
En lnea
Ilusin o realidad?
Darvein
Desconectado
Mensajes: 182
En lnea
Ilusin o realidad?
Darvein
Desconectado
Mensajes: 182
{
for (int i = 1 ; i <= f ; i++)
{
System.out.println ();
for (int j = 1 ; j <= c ; j++)
{
System.out.print ("[" + M [i] [j] + "]");
}
}
}
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);
}
}
}
principal*/
Cdigo:
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 ("Inserte pos[" + i + "][" + j
+ "]: ");
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 ("[" + M [i] [j] + "]");
}
}
}
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--;
}
}
R: \n");
S: \n");
");
");
}
/*Dada una matris intercambiar los elementos de la
primera columna con la ultima columna*/
Cdigo:
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 ();
}
}
}
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 ("[" + M [i] [j] + "]");
}
}
}
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 ("Inserte filas de la matris:
");
int f = Leer.datoInt ();
System.out.print ("Inserte columnas de la
matris: ");
int c = Leer.datoInt ();
System.out.print ("\nLLENANDO MATRIS : \n");
h.llenar (M, f, c);
System.out.print ("\nLA MATRIS ORIGINAL : ");
h.mostrar (M, f, c);
System.out.print ("\n\nLA MATRICES INTERCAMBIADA
: ");
h.intercambiar (M, f, c);
h.mostrar (M, f, c);
}
}
/* Contar el numero de digitos de cada elemento de
una matris */
Cdigo:
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 ("Inserte pos[" + i + "][" + j
+ "]: ");
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 ("[" + M [i] [j] + "]");
}
}
}
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 ("\n[" + M [i] [j] + "] tiene:
" + digitos (M [i] [j]) + " digito(s)");
}
}
}
int digitos (int n)
{
int contador = 0;
while (n != 0)
{
n = n / 10;
contador++;
}
return (contador);
}
Desconectado
Mensajes: 182
c)
{
for (int i = 1 ; i <= f ; i++)
{
System.out.println ();
for (int j = 1 ; j <= c ; j++)
{
System.out.print ("[" + M [i] [j] + "]");
}
}
una
13
23
33
1.Cdigo
1. class suma {
2.
3.
4.
5.
suma = n1 + n2;
6.
7.
8.
System.out.println(suma);
9.
10. }
2.Cdigo
1. class suma
2. {
3.
4.
5.
6.
suma = n1 + n2;
7.
8.
9. }
3.Cdigo
1. class cuadrado
2. {
3.
4.
5.
6.
7.
8.
9. }
En lnea
Niara
Desconecta
do
El ejercicio 2 :B
Mensajes: 23
Cdigo
1. public class suma
2. {
Niara
3.
4.
5.
6.
suma=n1+n2;
7.
8.
9. }
En lnea
Tengo demasiadas fantasas para ser una ama de casa.
Marilyn Monroe
NullP0inter
Desconecta
do
Aqu esta el n 8:
Mensajes: 9
Cdigo
1.
2.
3. final
int m=10;
4.
5.
6.
7.
8.
9.
10.
11.
array[i]=
alphabet.charAt(r.nextInt(N));
12.
13.
switch(array[i]){
14.
15.
case 'a':
System.out.println("vocal: " + array[i]);break;
16.
case 'e':
System.out.println("vocal: " + array[i]);break;
17.
case 'i':
System.out.println("vocal: " + array[i]);break;
18.
case 'o':
System.out.println("vocal: " + array[i]);break;
19.
case 'u':
System.out.println("vocal: " + array[i]);break;
20.
default:
21.
22.
System.out.println("consonante: " + array[i]);
23.
24.
25.
}
}
26.
27.
dentro del ciclo algunas condiciones que tendran que revisar el *contador y si este es
primo accedes a otras condiciones que te diran si es perfecto,
si las dos condiciones anteriores se cumplen entonces imprimes/despliegas el numero
y si no pues no haces nada
saludos y espero no me den de baja la cuarta cuenta jajajaa
*contador=numero que va cambiando en el ciclo puede ser i o j o etc.
caballero maldito...