Sei sulla pagina 1di 11

ESCUELA SUPERIOR POLITÉCNICA DE

CHIMBORAZO

FACULTAD DE INFORMÁTICA Y ELECTRÓNICA

Escuela de Ingeniería en Electrónica, Control y Redes Industriales

Nombre: Erika Escobar TERCERO B Código: 999


Materia: Lenguaje de Programación II

TAREA

1. Realizar un programa en JAVA que permita obtener los N primeros


números pares

import java.util.Scanner;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

* @author erikaescobar

*/

public class EJERCICIOS {

public static void main(String[] args)

Scanner sc = new Scanner(System.in); //PARA EL INGRESO DE


DATOS

System.out.println ("Introduzca cuantos numeros pares desea visualizar:


"); //PEDIDO

int n = sc.nextInt(); //N NUMEROS PARES


int a;

int cont;

cont=1;

System.out.println("Los numeros pares son: "); //SALIDA

while ( cont <= n ) {

a=cont*2;

System.out.println ( a );

cont ++;

}
2. Realizar un programa en JAVA que permita obtener los N primeros
números primos

import java.util.Scanner;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

* @author erikaescobar

*/

public class EJERCICIOS {

public static void main(String[] args)

Scanner sc = new Scanner(System.in); //PARA EL INGRESO DE DATOS

System.out.println("Introduzca cuantos numeros primos desea visualizar:


"); //PEDIDO

int n = sc.nextInt(); //N NUMEROS PRIMOS

int a,j,k,i,cont;

j=1;

k=0;

System.out.println("Los numeros primos son: "); //SALIDA


while (k<=n) {

cont=0;

i=1;

while (i<=j)

if (j%i==0)

cont=cont+1;

i=i+1;

if (cont ==2)

System.out.println(j);

k=k+1;

j=j+1;

}
3. Realizar un programa en JAVA que permita obtener: Una base
elevado a un exponente a través de sumas sucesivas

import java.util.Scanner;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

* @author erikaescobar

*/

public class EJERCICIOS {


public static void main(String[] args)

Scanner sc = new Scanner(System.in); //PARA EL INGRESO DE DATOS

System.out.println("Introduzca la base de la potencia: "); //PEDIDO

int A = sc.nextInt(); //BASE

System.out.println("Introduzca la potencia: "); //PEDIDO

int B = sc.nextInt(); //EXPONENTE

int i,k,s,p;

s=0;

i=1;

p=A;

System.out.println("El resultado es : ");

while(i<B)

k=1;

s=0;

while(k<=p)

s=s+A;

k=k+1;

i=i+1;

A=s;

}
System.out.println(s);

4. Realizar un programa en JAVA que permita obtener el factorial de


un numero a través de sumas sucesivas

import java.util.Scanner;

/*
* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

* @author erikaescobar

*/

public class EJERCICIOS {

public static void main(String[] args)

Scanner sc = new Scanner(System.in); //PARA EL INGRESO DE DATOS

System.out.println("Introduzca el numero que desea obtener su factorial: ");


//PEDIDO

int n = sc.nextInt(); //NUMERO

int k,p,i,A,b,a;

k=2;

p=1;

System.out.println("Su factorial es: ");

while(k<=n)

a=k;

b=p;

i=1;
A=0;

while(i<=a)

A=A+b;

i=i+1;

p=A;

k=k+1;

System.out.println(p);

}
5. Realizar un programa en JAVA que permita obtener los N primeros
múltiplos de 5.

import java.util.Scanner;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

* @author erikaescobar

*/

public class EJERCICIOS {

public static void main(String[] args)

Scanner sc = new Scanner(System.in); //PARA EL INGRESO DE


DATOS

System.out.println ("Introduzca cuantos múltiplos de 5 desea visualizar:


"); //PEDIDO

int n = sc.nextInt(); //N NUMEROS PARES

int a;

int cont;

cont=1;

System.out.println("Los numeros múltiplos de 5 son: "); //SALIDA


while ( cont <= n ) {

a=cont*5;

System.out.println ( a );

cont ++;

Potrebbero piacerti anche