Académique Documents
Professionnel Documents
Culture Documents
com/2012/04/mi-primer-programa-en-java-2/
http://algoritmosurgentes.com/java.php?f=raiz_cuadrada%3Dpow(numero
%2C0.5)
http://vicman.zzl.org/Curso%20de%20Algoritmos/Ejercicios
%20resueltos.html
http://www.desarrolloweb.com/articulos/2225.php
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
int n=0;
do{
n++;
System.out.print(n+" ");
}while(n<10);
1.
20
1
2
3
4
5
Reportar
los
siguiente
25 30 35 70 75 80
public class Ejemplo
{
public static void main(String[] args)
{
for (int i = 20; i < 80; i = i + 5)
System.out.print(i + " ");
serie:
6
7
8
2.
Reportar
100 98 96 94 56 54 52 50
1
2
3
4
5
6
7
8
9
la
siguiente
serie:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.Scanner;
public class Ejemplo
{
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1.
n = scan.nextInt();
for (int i = 1; i <= n; i++)
{
System.out.print(i + ") Ingrese un numero: ");
x = scan.nextInt();
if (x==0)
c++;
else
{
if(x>0)
cp++;
else
cn++;
}
}
System.out.println("La cantidad de positivos son: " + cp);
System.out.println("La cantidad de negativos son: " + cn);
System.out.println("La cantidad de ceros son: " + c);
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
1.
alcular
P = 1*2*3*4*5*6**50
1
2
3
4
5
6
7
8
9
10
11
2.
el
siguiente
producto:
1
2
3
4
5
6
7
8
9
10
11
1
2
3
4
5
6
7
8
9
10
5
6
7
8
9
10
11
12
1.
for(i=1;i<=50;i++)
if(i%2==0) sp=sp+i;
else si=si+i;
System.out.println("La suma de pares es : "+sp);
System.out.println("La suma de impares es : "+si);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2.
1
2
3
4
5
6
7
8
9
10
11
12
13
1.
1
2
3
4
5
6
7
8
import java.util.Scanner;
public class Ejemplo
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n,i;
9
10
11
12
13
14
15
16
17
18
19
2.
double f=1;
do{
System.out.print("Ingrese numero positivo o cero : ");
n=in.nextInt();
}while(n<0);
for(i=1;i<=n;i++)
f=f*i;
System.out.println("El factorial es : "+f);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
3.
import java.util.Scanner;
public class Ejemplo
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n,i;
double x,s=0,p;
do{
System.out.print("Valor de n : ");
n=in.nextInt();
}while(n<=0);
for(i=1;i<=n;i++)
{
System.out.print("Ingrese numero : ");
x=in.nextDouble();
s=s+x;
}
p=s/n;
System.out.println("El Promedio es : "+p);
}
}
1
2
3
4
5
6
7
8
9
10
11
import java.util.Scanner;
public class Ejemplo
{
public static void main(String[] args)
{
Scanner in =new Scanner(System.in);
int n,i,x,sp=0,si=0,cp=0,ci=0;
double mi;
do{
System.out.print("Valor de n : ");
n=in.nextInt();
}while(n<=0);
for(i=1;i<=n;i++)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
4.
}
if(cp>0)
{
System.out.println("La
System.out.println("La
}
else
System.out.println("No
if(ci>0)
{
mi=(double)si/ci;
System.out.println("La
}
else
System.out.println("No
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.util.Scanner;
public class Ejemplo
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n,i,x,sp=0,sn=0,cp=0,cn=0;
double pp,pn;
do{
System.out.print("Valor de n : ");
n=in.nextInt();
}while(n<=0);
for(i=1;i<=n;i++)
{
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
5.
}
if(cp>0)
{
pp=(double)sp/cp;
System.out.println("El
}
else
System.out.println("No
if(cn>0)
{
pn=(double)sn/cn;
System.out.println("El
}
else
System.out.println("No
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.util.Scanner;
public class Ejemplo
{
public static void main(String[] args)
{
int n,i;
double x,maximo,minimo;
Scanner in = new Scanner(System.in);
do{
System.out.print("Valor de n : ");
n=in.nextInt();
}while(n<=0);
maximo=-1e30;
minimo=1e30;
for(i=1;i<=n;i++)
{
16
17
18
19
20
21
22
23
24
25
26
27
6.
}
System.out.println("El maximo es : "+maximo);
System.out.println("El minimo es : "+minimo);
}
Calcular
la
suma
de
los
S=1 1/2 + 1/3 1/4 + 1/5 1/6 + 1/n
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
7.
trminos
de
la
serie:
import java.util.Scanner;
public class Ejemplo
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
int n,i;
double s=0;
do{
System.out.print("Valor de n : ");
n=sc.nextInt();
}while(n<=0);
for(i=1;i<=n;i++)
{
if(i%2==0) s=s-1.0/i;
else s=s+1.0/i;
}
System.out.println("La sumatoria es : "+s);
1
2
3
4
5
6
7
8
9
import java.util.Scanner;
public class Ejemplo
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n,i;
double p=1,s=0,t;
do{
System.out.print("Numero de terminos : ");
10
11
12
13
14
15
16
17
18
19
20
21
22
23
8.
n=in.nextInt();
}while(n<=2);
for(i=1;i<=n;i++)
{
t=p+s;
System.out.print(t+"
p=s;
s=t;
}
System.out.println();
");
Leer nmeros hasta que el ltimo nmero ingresado sea -99 (este no se toma en
cuenta para el clculo) y reportar el mayor.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
9.
S=
import java.util.Scanner;
public class Ejemplo
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
int n,i=0;
double x,mayor;
mayor=-1e30;
do{
System.out.print("Ingrese numero (-99 para finalizar) : ");
x=sc.nextDouble();
if(x!=-99)
{
i++;
if(x>mayor) mayor=x;
}
}while(x!=-99);
if(i>0)
System.out.println("El mayor es : "+mayor);
else
System.out.println("No se ingresaron numeros");
}
}
Calcular
1
+
x^2/2!
la
x^3/3!
x^4/4!
1
2
3
4
import java.util.Scanner;
public class Ejemplo
{
public static void main(String[] args)
sumatoria:
+
x^n/n!
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
10.
Programa para ingresar un nmero entero positivo y reportar todos sus divisores.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
11.
import java.util.Scanner;
public class Ejemplo
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int num;
do{
System.out.print("Ingrese numero :");
num=in.nextInt();
}while(num<=0);
int d;
System.out.println("Los divisores del numero son :");
for(d=1;d<=num;d++)
if(num%d==0) System.out.print(d+" ");
System.out.println();
}
}
1
2
3
4
5
6
import java.util.Scanner;
public class Ejemplo
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int num;
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
12.
do{
System.out.print("Ingrese numero :");
num=in.nextInt();
}while(num<=0);
int n;
int d=1;
do{
d=d+1;
}while( num%d!=0 && d*d<=num);
if(d*d>num) n=1;
else n=0;
if(n==1)
System.out.println("El numero es primo");
else
System.out.println("El numero no es primo");
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
13.
import java.util.Scanner;
public class Ejemplo
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int num;
do{
System.out.print("Ingrese numero :");
num=in.nextInt();
}while(num<=0);
int d,sum=0;
for(d=1;d<num;d++)
if(num%d==0) sum=sum +d;
if(sum==num)
System.out.print("El numero es Perfecto!!");
else
System.out.print("El numero NO es Perfecto!!");
System.out.println();
}
}
import java.util.Scanner;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
14.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.util.Scanner;
public class Ejemplo
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int x,y;
do{
System.out.print("Ingrese primer numero :");
x=in.nextInt();
}while(x<0);
do{
System.out.print("Ingrese el segundo numero : ");
y=in.nextInt();
}while(y<0);
int d=2,p=1,a,b;
a=x;
b=y;
while(d<=a && d<=b)
if(a%d==0 && b%d==0)
{
p=p*d;
a=a/d;
b=b/d;
}
else
d++;
System.out.println("El m.c.d de "+x+" y "+y+" es : "+p);
}
}
27
28
29
30
31
15.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
16.
import java.util.Scanner;
public class Ejemplo
{
public static void main(String[] args)
{
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import java.util.Scanner;
public class Ejemplo
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int num, invert=0,aux, digit;
System.out.print("Ingresa numero : ");
num = sc.nextInt();
aux=num;
while(aux>0)
{
digit=aux%10;
invert=invert*10 + digit;
aux=aux/10;
}
if(num==invert)
System.out.println("El numero es Capicua!!");
else
System.out.println("El numero NO es Capicua!!");
}
20
21
22
23
17.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.Scanner;
public class Ejemplo
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
int num,base;
String result=" ";
System.out.print("Ingrese el numero en base 10 : ");
num= sc.nextInt();
do{
System.out.print("Ingrese la base : ");
base= sc.nextInt();
}while(base>=9);
if(num<base)
result= num + result;
while(num>=base)
{
result= num%base + result;
num=num/base;
if(num<base)
result= num + result;
}
System.out.println("El numero en base "+base+" es : "+result);
}
}
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
1, 1, 2, 3, 5, 8, 13, 21,
30.
Leer Nmeros (el ultimo numero es -99) y obtener el mayor.
31.
Calcular
la
s
x^2/2!
x^3/3!
x^4/4!
sumatoria
+
x^n/n!