Professional Documents
Culture Documents
1.
1
2
3
4
5
6
7
8
9
10
o
1
2
3
4
5
6
7
8
9
o
1
2
3
4
5
6
7
8
9
2.
int n=0;
do{
n++;
System.out.print(n+" ");
}while(n<10);
Reportar
20 25 30 35 70 75 80
1
2
3
4
5
6
7
8
los
siguiente
serie:
3.
Reportar
100 98 96 94 56 54 52 50
1
2
3
4
5
6
7
8
9
4.
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
5.
import java.util.Scanner;
public class Ejemplo
{
1
2
3
4
5
6
7
8
9
import java.util.Scanner;
public class Ejemplo
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int n, x, cp = 0, cn = 0, c=0;
System.out.print("Ingrese la cantidad de numeros a revisar: ");
n = scan.nextInt();
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
6.
}
}
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);
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
import java.util.Scanner;
public class Ejemplo
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int n, x, cv = 0, cm = 0;
double pv,pm;
System.out.print("Ingrese numero de personas : ");
n = scan.nextInt();
System.out.print("Ingrese sexo n"
+ "[1] Varon n"
+ "[2] Mujer n");
for (int i = 1; i <= n; i++)
{
System.out.print("Persona " + i + " : ");
x = scan.nextInt();
if (x==1)
cv++;
else
{
if(x==2)
cm++;
}
}
pv=(cv*100)/n;
pm=(cm*100)/n;
System.out.println("El porcentaje de varones es : " + pv + "%");
26
27
28
29
30
31
32
33
7.
Calcular
P = 1*2*3*4*5*6**50
1
2
3
4
5
6
7
8
9
10
11
8.
el
siguiente
producto:
1
2
3
4
5
6
7
8
9
10
11
9.
1
2
3
4
5
6
7
8
9
10
10.
1
2
3
4
5
6
7
8
9
10
11
12
11.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
12.
1
2
3
4
5
6
7
8
9
10
11
12
13
13.
1
2
3
import java.util.Scanner;
public class Ejemplo
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
14.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
15.
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
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;
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
34
35
36
37
38
39
40
41
42
43
44
16.
double mi;
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.nextInt();
if(x%2==0)
{
cp++;
sp=sp+x;
}
else
{
ci++;
si=si+x;
}
}
if(cp>0)
{
System.out.println("La suma de los numeros pares es : "+sp);
System.out.println("La cantidad de numeros pares es : "+cp);
}
else
System.out.println("No se Ingresaron numeros pares");
if(ci>0)
{
mi=(double)si/ci;
System.out.println("La media de los impares es : "+mi);
}
else
System.out.println("No se Ingresaron numeros impares");
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,x,sp=0,sn=0,cp=0,cn=0;
double pp,pn;
10
11
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
45
46
47
17.
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.nextInt();
if(x>0)
{
cp++;
sp=sp+x;
}
else
if(x<0)
{
cn++;
sn=sn+x;
}
}
if(cp>0)
{
pp=(double)sp/cp;
System.out.println("El Promedio de positivos es : "+pp);
}
else
System.out.println("No se Ingresaron Positivos");
if(cn>0)
{
pn=(double)sn/cn;
System.out.println("El Promedio de Negativos es : "+pn);
}
else
System.out.println("No se Ingresaron Negativos");
1
2
3
4
5
6
7
8
9
10
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 : ");
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
18.
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
19.
n=in.nextInt();
}while(n<=0);
maximo=-1e30;
minimo=1e30;
for(i=1;i<=n;i++)
{
System.out.print("Ingrese numero : ");
x=in.nextDouble();
if(x>maximo) maximo=x;
if(x<minimo) minimo=x;
}
System.out.println("El maximo es : "+maximo);
System.out.println("El minimo es : "+minimo);
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
import java.util.Scanner;
public class Ejemplo
{
public static void main(String[] args) {
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
20.
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
21.
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
S=
1
+
x^2/2!
la
x^3/3!
x^4/4!
sumatoria:
+
x^n/n!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
22.
import java.util.Scanner;
public class Ejemplo
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n,i;
double p=1,x,f=1,s=1;
System.out.print("Ingrese valor de x : ");
x=sc.nextDouble();
do{
System.out.print("Valor de n : ");
n=sc.nextInt();
}while(n<0);
for(i=1;i<=n;i++)
{
f=f*i;
p=p*x;
s=s+p/f;
}
System.out.println("La sumatoria es : "+s);
}
}
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
23.
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
import java.util.Scanner;
public class Ejemplo
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
24.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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();
}
}
25.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
26.
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=2;
System.out.print("Factores primos : ");
while(num>1)
{
while(num % d !=0) d=d+1;
System.out.print(d+" ");
num=num/d;
}
System.out.println("");
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
23
24
25
26
27
28
29
30
31
27.
d++;
System.out.println("El m.c.d de "+x+" y "+y+" es : "+p);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
28.
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
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)
16
17
18
19
20
21
22
23
29.
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);
}
}
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
}
}
char sexo;
int edad;
System.out.print("Cuantos aos tiene:");
edad=in.nextInt();
in.nextLine();
System.out.println("Cual es su sexo(M/F):");
sexo=in.nextLine().charAt(0);
if(edad>=18)
if(sexo=='M')
System.out.print("Hombre mayor de edad");
else
System.out.print("Mujer mayor de edad");
else
if(sexo=='M')
System.out.print("Hombre menor de edad");
else
System.out.print("Mujer menor de edad");