Sunteți pe pagina 1din 10

1.- REPORTAR NMEROS DEL 1 AL 10.

Resolvemos el problema usando while public static void main (String args []) { int n=0; while(n<10) { n++; System.out.print(n+"n"); } } Resolvemos el problema usando do while public static void main (String args []) { int n=0; do{ n++; System.out.print(n+" "); }while(n<10); } Resolvemos el problema usando for public static void main (String args []) { int n=0; for(int i=1;i<=10;i++) { System.out.print(i+" "); } } 2.-REPORTAR LOS SIGUIENTE SERIE: 20 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 + " "); } } 3.-Reportar la siguiente serie: 100 98 96 94 56 54 52 50 public class Ejemplo { public static void main(String[] args) { for(int i=100;i>=50;i=i-2) System.out.print(i+" "); } } 3.-INGRESAR N NMEROS ENTEROS Y REPORTAR LA CANTIDAD DE PARES Y LA CANTIDAD DE IMPARES. import java.util.Scanner; public class Ejemplo

{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n, x, cp = 0, ci = 0; System.out.print("Ingrese la cantidad de numeros a revisar: "); n = scan.nextInt(); for (int i = 1; i <= n; i++) { System.out.print(i + ") Ingrese un numero: "); x = scan.nextInt(); if (x % 2 == 0) cp++; else ci++; } System.out.println("La cantidad de pares son: " + cp); System.out.println("La cantidad de impares son: " + ci); } } 4.-INGRESAR N NMEROS Y REPORTAR LA CANTIDAD DE POSITIVOS, NEGATIVOS Y CEROS. 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(); 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); } }

5.-INGRESAR EL SEXO DE N PERSONAS Y REPORTAR EL PORCENTAJE DE HOMBRES Y EL PORCENTAJE DE MUJERES. 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 + "%"); System.out.println("El porcentaje de mujeres es : " + pm + "%"); } } 6.-CALCULAR EL SIGUIENTE PRODUCTO: P = 1*2*3*4*5*6**50 public class Ejemplo { public static void main(String[] args) { double prodt=1; for(int i=1;i<=50;i++) prodt=prodt*i; System.out.println("El producto es : " + prodt); } } 7.-CALCULAR LA SUMATORIA DE LOS NMEROS ENTEROS DEL 1 AL 100. public class Ejemplo { public static void main(String[] args) { int sum=0; for(int i=1;i<=100;i++) sum=sum+i;

System.out.println("La suma es : "+sum); } } 8.-CALCULAR LA SUMA DE LOS CUADRADOS DE LOS 15 PRIMEROS NMEROS NATURALES. public class Ejemplo { public static void main(String[] args) { int i,sc=0; for(i=1;i<=15;i++) sc=sc+i*i; System.out.println("La suma de los cuadrados de los primeros 15 nmeros es : "+sc); } } 9.-SE DESEA CALCULAR INDEPENDIENTEMENTE LA SUMA DE LOS PARES E IMPARES COMPRENDIDOS ENTRE 1 Y 50. public class Ejemplo { public static void main(String[] args) { int i,sp=0,si=0; 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); } } 10.-SE DESEA CALCULAR INDEPENDIENTEMENTE LA SUMA DE LOS IMPARES Y EL PRODUCTO DE TODOS LOS IMPARES COMPRENDIDOS ENTRE 20 Y 80 public class Ejemplo { public static void main(String[] args) { int i,si=0; double pi=1; for(i=20;i<=80;i++) if(i%2!=0) { si=si+i; pi=pi*i; } System.out.println("La suma es : "+si); System.out.println("El producto es : "+pi); } } 11.-INGRESAR UN NMERO ENTERO POSITIVO Y REPORTAR SU TABLA DE MULTIPLICAR. public class Ejemplo { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int n;

System.out.print("Ingresa un numero entero positivo : "); n=sc.nextInt(); System.out.println("Tabla de multiplicar del "+n); for(int i=1;i<=12;i++) System.out.println(n+"x"+i+"="+n*i); } } 12.-CALCULAR EL FACTORIAL DE UN NMERO ENTERO MAYOR O IGUAL QUE CERO. import java.util.Scanner; public class Ejemplo { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n,i; 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); } } 13.-INGRESAR N NMEROS. SE PIDE CALCULAR EL PROMEDIO DE ELLOS 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); } } 14.-INGRESAR N NMEROS ENTEROS, VISUALIZAR LA SUMA DE LOS NMEROS PARES DE LA LISTA, CUANTOS PARES EXISTEN Y CUL ES LA MEDIA DE LOS NMEROS IMPARES.

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++) { 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"); } } 15.-INGRESAR N NMEROS Y REPORTAR EL PROMEDIO DE LOS POSITIVOS Y EL PROMEDIO DE LOS NEGATIVOS. 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++) { 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"); } } 16.-INGRESAR N NMEROS, CALCULAR EL MAYOR Y EL MENOR DE ELLOS. 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++) { 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); } } 17.-CALCULAR LA SUMA DE LOS N TRMINOS DE LA SERIE: S=1 1/2 + 1/3 1/4 + 1/5 1/6 + 1/n 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); } } 18.-REALIZAR UN PROGRAMA QUE ESCRIBA LOS N TRMINOS DE LA SERIE DE FIBONACCI 1, 1, 2, 3, 5, 8, 13, 21, 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 : "); 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();

} } 19.-LEER NMEROS HASTA QUE EL LTIMO NMERO INGRESADO SEA -99 (ESTE NO SE TOMA EN CUENTA PARA EL CLCULO) Y REPORTAR EL MAYOR. 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"); } } 20.-CALCULAR LA SUMATORIA: S= 1 + X + X^2/2! + X^3/3! + X^4/4! + + X^N/N! SE DEBE INGRESAR X REAL Y N ENTERO POSITIVO 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); } }

21.- PROGRAMA PARA INGRESAR UN NMERO ENTERO POSITIVO Y REPORTAR TODOS SUS DIVISORES. 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(); } } 22.-INGRESAR UN NMERO ENTERO Y REPORTAR SI ES PRIMO. UN NMERO ES PRIMO CUANDO ES DIVISIBLE POR SI MISMO Y LA UNIDAD. 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 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"); } } 22.-INGRESAR UN NMERO ENTERO POSITIVO Y REPORTAR SI ES PERFECTO. UN NMERO ES PERFECTO SI ES IGUAL A LA SUMA DE DIVISORES MENORES QUE L. POR EJEMPLO 6 ES PERFECTO PUES ES IGUAL 1 + 2 + 3. 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(); } } Ingresar un nmero y reportar todos sus factores primos. Por ejemplo si ingresamos 12 debe reportar 2x2x3. Si ingresamos 25 se debe reportar 55. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 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=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(""); } } Ingresar 2 nmeros enteros positivos y reportar su mximo comn divisor. 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 28 29 30 31 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); } } Ingresar un nmero entero positivo y reportar su suma de dgitos. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 import java.util.Scanner; public class Ejemplo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num, sum=0, digit; do { System.out.print("Ingrese un numero : "); num = sc.nextInt(); }while(num<0);

while(num>0) { digit=num%10; sum=sum+digit; num=num/10; } System.out.println("La suma de sus digitos es : "+sum); } } Ingresar un numero entero positivo y reportar si es capica 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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!!"); }

} Ingresar un numero entero en base 10 y reportar el numero en base b ( entre 2 y 9) 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); }

} Se desea calcular independientemente la suma de los pares e impares comprendidos entre 1 y 50 (incluidos los extremos). Calcular y visualizar la suma y el producto de los nmeros impares comprendidos entre 20 y 80. Leer n nmeros enteros y obtener el promedio de los positivos y el promedio de los negativos. Calcular la suma de los cuadrados de los nmeros desde el 1 hasta el 15. Se ingresan n nmeros. Se pide calcular el promedio de ellos Ingresar n nmeros enteros, visualizar la suma de los nmeros pares de la lista, cuantos pares existen y cul es la media de los nmeros impares. Desarrolle un programa que determine en un conjunto de nmeros naturales. Cuantos son menores de 15 Cuantos son mayores de 50 Cuantos estn comprendidos entre 25 y 45. Calcular el factorial de un numero n>=0 Ingresar un valor de x y un valor n positivo reportar la potencia de x elevado a la n. Imprimir las 10 primeras potencias de 4. Ingresar n nmeros, Calcular el mximo y el mnimo de ellos. Realizar un programa que escriba los n trminos de la serie de Fibonacci 1, 1, 2, 3, 5, 8, 13, 21, Leer Nmeros (el ultimo numero es -99) y obtener el mayor. Calcular la sumatoria s = 1 + x + x^2/2! + x^3/3! + x^4/4! + + x^n/n! Se debe ingresar x real y n entero positivo

CATEGORIAS: J2SE, JAVA 8 Responses so far. Liz dice: 28 junio, 2012 a las 10:04 PM e^x = 1 + x + x^2/2! + x^3/3! + x^4/4! + + x^n/n! me puedes ayudar con este algoritmo en visual basic, te lo agradeceria mucho Responder juan carlos dice: 28 junio, 2012 a las 10:41 PM Esta seccin es de Java ,pero como lo necesitas convert a varios lenguaje,gracias por preguntar JAVA 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 { 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); } } VB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

17 18 19 20 21 Module Module1 Sub Main() Dim n As Integer, i As Integer Dim p As Double = 1, x As Double, f As Double = 1, s As Double = 1 Console.Write("Ingrese valor de x :") x = Double.Parse(Console.ReadLine()) Do Console.Write("Valor de n : ") n = Int16.Parse(Console.ReadLine()) Loop While n < 0 For i = 1 To n f=f*i p=p*x s=s+p/f Next Console.WriteLine("La sumatoria es : " & s) Console.ReadLine() End Sub End Module 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 26 27 28 29

30 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { int n,i; double p=1,x,f=1,s=1; Console.Write("Ingrese valor de x :"); x=double.Parse(Console.ReadLine()); do{ Console.Write("Valor de n : "); n=Int16.Parse(Console.ReadLine()); }while(n<0); for(i=1;i<=n;i++) { f=f*i; p=p*x; s=s+p/f; } Console.WriteLine("La sumatoria es : "+s); Console.ReadLine(); } } } Responder Nely dice: 9 febrero, 2013 a las 9:24 PM Help me necesito que me ayuden con estos problemas ingresar un numero, si es para sumar todos los pares antecesores a el y si es impar lo mismo sumar sus antecesores eso de las llaves y el else se me confunde.. me gustaba mas pascal o c mmm ingrese dos numeros, verifique si el segundo valor es multiplo del primero graaacias por ayudarme Responder daniel brena dice: 10 abril, 2013 a las 12:44 AM //En java creo que ya fue demasiado tarde espero y te sirva 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 antecesores{ public static void main(String[] args){ Scanner t = new Scanner(System.in); int suma = 0; //int impar = 0; int n = 0; System.out.println("Dame un numero"); n = t.nextInt(); if(n % 2 == 0){ System.out.println("Es par"); for(int i = 1; i<= n; i++){ suma +=i; } }else{ System.out.println("Es impar "); for(int i = 1; <= n; i++){ suma += i; } } System.out.println("Suma es: " + suma); } }

S-ar putea să vă placă și