Está en la página 1de 21

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA

Programacin Orientada A Objetos


Cdigo 301403
2.015_I
UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA UNAD
PROGRAMACION ORIENTADA A OBJETOS
PRE-SABER PRCTICO

Presentacin
GUSTAVO ALBERTO ANGULO JUSTINICO 1010167969
Grupo 301403_53
TUTOR
CESAR ORLANDO JIMNEZ ANGARITA

BOGOTA D.C, COLOMBIA


FEBRERO DE 2015

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I
PROBLEMAS PROPUESTOS
Pgina 38
1. Se cargan por teclado tres nmeros distintos. Mostrar por pantalla el mayor de ellos.
import java.io.*;
public class EstructuraCondicionalAnidada3 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int num;
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Ingrese el primer valor: ");
num=Integer.parseInt(leerdigito.readLine());
if (num==0)
{
System.out.print("Se ingres el cero");
}
else
{
if (num>0)
{
System.out.print("Se ingres un valor positivo");
}
else
{
System.out.print("Se ingres un valor negativo");
}
}
}
}

2. Se ingresa por teclado un valor entero, mostrar una leyenda que indique si el
nmero es positivo, nulo o negativo.
3.
import java.io.*;
public class EstructuraCondicionalAnidada3 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int num;
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Ingrese el primer valor: ");
num=Integer.parseInt(leerdigito.readLine());

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I
if (num==0)
{
System.out.print("Se ingres el cero");
}
else
{
if (num>0)
{
System.out.print("Se ingres un valor positivo");
}
else
{
System.out.print("Se ingres un valor negativo");
}
}
}
}

4. Confeccionar un programa que permita cargar un nmero entero positivo de hasta


tres cifras y muestre un mensaje indicando si tiene 1, 2, o 3 cifras. Mostrar un
mensaje de error si el nmero de cifras es mayor.
5.
import java.io.*;
public class EstructuraCondicionalAnidada4 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int num;
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Ingrese un valor de hasta tres dgitos positivo");
num=Integer.parseInt(leerdigito.readLine());
if (num<10)
{
System.out.print("Tiene un dgito");
}
else
{
if (num<100)
{
System.out.print("Tiene dos dgitos");
}
else
{
if (num<1000)
{
System.out.print("Tiene tres dgitos");
}
else

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I
{
System.out.print("Error en la entrada de datos.");
}
}
}
}
}

6. Un postulante a un empleo, realiza un test de capacitacin, se obtuvo la siguiente


informacin: cantidad total de preguntas que se le realizaron y la cantidad de
preguntas que contest correctamente. Se pide confeccionar un programa que
ingrese los dos datos por teclado e informe el nivel del mismo segn el porcentaje
de respuestas correctas que ha obtenido, y sabiendo que:
Nivel mximo: Porcentaje>=90%.
Nivel medio: Porcentaje>=75% y <90%.
Nivel regular: Porcentaje>=50% y <75%.
Fuera de nivel: Porcentaje<50%.
import java.io.*;
public class EstructuraCondicionalAnidada5 {
public static void main(String[] arg) throws NumberFormatException,
IOException
{
int totalPreguntas,totalCorrectas;
BufferedReader leerdigito1 = new BufferedReader(new
InputStreamReader(System.in));
BufferedReader leerdigito2 = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Ingrese la cantidad total de preguntas del examen:");
totalPreguntas=Integer.parseInt(leerdigito1.readLine());
System.out.println("Ingrese la cantidad total de preguntas contestadas
correctamente:");
totalCorrectas=Integer.parseInt(leerdigito2.readLine());
int porcentaje=totalCorrectas * 100 / totalPreguntas;
if (porcentaje>=90)
{
System.out.print("Nivel mximo");
}
else
{
if (porcentaje>=75)
{
System.out.print("Nivel medio");
}
else
{

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I
if (porcentaje>=50)
{
System.out.print("Nivel regular");
}
else
{
System.out.print("Fuera de nivel");
}
}
}
}

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I
PROBLEMAS PROPUESTOS
Pgina 45
1. Se ingresan tres valores por teclado, si todos son iguales se imprime la suma del
primero con el segundo y a este resultado se lo multiplica por el tercero.
2.
import java.io.*;
public class CondicionesCompuestas4 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int num1,num2,num3;
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Ingrese primera Valor:");
num1=Integer.parseInt(leerdigito.readLine());
System.out.println("Ingrese segunda Valor: ");
num2=Integer.parseInt(leerdigito.readLine());
System.out.println("Ingrese tercera Valor:");
num3=Integer.parseInt(leerdigito.readLine());
if (num1==num2 && num1==num3)
{
int suma=num1 + num2;
System.out.print("La suma del primero y segundo:");
System.out.println(suma);
int producto=suma * num3;
System.out.print("La suma del primero y segundo multiplicado por el tercero:");
System.out.print(producto);
}
}
}

3. Se ingresan por teclado tres nmeros, si todos los valores ingresados son menores a
10, imprimir en pantalla la leyenda "Todos los nmeros son menores a diez".
import java.io.*;
public class CondicionesCompuestas5 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int num1,num2,num3;
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Ingrese primera Valor:");
num1=Integer.parseInt(leerdigito.readLine());
System.out.println("Ingrese segunda Valor: ");
num2=Integer.parseInt(leerdigito.readLine());
System.out.println("Ingrese tercera Valor:");
num3=Integer.parseInt(leerdigito.readLine());

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I

if (num1<10 && num2<10 && num3<10)


{
System.out.print("Todos los nmeros son menores a diez");
}
}

4. Se ingresan por teclado tres nmeros, si al menos uno de los valores


ingresados es menor a 10, imprimir en pantalla la leyenda "Alguno de los
nmeros es menor a diez".
import java.io.*;
public class CondicionesCompuestas6 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int num1,num2,num3;
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Ingrese primera Valor:");
num1=Integer.parseInt(leerdigito.readLine());
System.out.println("Ingrese segunda Valor: ");
num2=Integer.parseInt(leerdigito.readLine());
System.out.println("Ingrese tercera Valor:");
num3=Integer.parseInt(leerdigito.readLine());
if (num1<10 || num2<10 || num3<10)
{
System.out.print("Alguno de los nmeros es menor a diez");
}
}
}

5. Posteriormente imprimir en pantalla en que cuadrante se ubica dicho punto. (1


Cuadrante si x > 0 Y y > 0 , 2 Cuadrante: x < 0 Y y > 0, etc.).
6.
import java.io.*;
public class CondicionesCompuestas7 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int x,y;
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Ingrese coordenada x:");
x=Integer.parseInt(leerdigito.readLine());
System.out.println("Ingrese coordenada y:");
y=Integer.parseInt(leerdigito.readLine());
if (x>0 && y>0)

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I
{
System.out.print("Se
}
else
{
if (x<0 && y>0)
{
System.out.print("Se
}
else
{
if (x<0 && y<0)
{
System.out.print("Se
}
else
{
System.out.print("Se
}
}
}
}

encuentra en el primer cuadrante");

encuentra en el segundo cuadrante");

encuentra en el tercer cuadrante");

encuentra en el cuarto cuadrante");

7. De un operario se conoce su sueldo y los aos de antigedad. Se pide confeccionar


un programa que lea los datos de entrada e informe:
8.
import java.io.*;
public class CondicionesCompuestas8 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
float sueldo;
int antiguedad;
System.out.println("Ingrese sueldo del empleado:");
sueldo=Float.parseFloat(leerdigito.readLine());
System.out.println("Ingrese su antiguedad en aos:");
antiguedad=Integer.parseInt(leerdigito.readLine());
if (sueldo<500 && antiguedad>10)
{
float aumento=sueldo * 0.20f;
float sueldoTotal=sueldo+aumento;
System.out.print("Sueldo a pagar:");
System.out.print(sueldoTotal);
}
else
{

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I
if (sueldo<500)
{
float aumento=sueldo * 0.05f;
float sueldoTotal=sueldo+aumento;
System.out.print("Sueldo a pagar:");
System.out.print(sueldoTotal);
}
else
{
System.out.print("Sueldo a pagar:");
System.out.print(sueldo);
}
}
}
}

PROBLEMAS PROPUESTOS
Pgina 56
1.

Escribir un programa que solicite ingresar 10 notas de alumnos y nos informe


cuntos tienen notas mayores o iguales a 7 y cuntos menores.

import java.io.*;
public class EstructuraRepetitivaWhile5 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int x,nota,conta1,conta2;
x=1;
conta1=0;
conta2=0;
while (x<=10)
{
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Ingrese nota:");
nota=Integer.parseInt(leerdigito.readLine());
if (nota>=7)
{
conta1=conta1 + 1;
}
else
{
conta2=conta2 + 1;
}
x=x + 1;
}
System.out.print("Cantidad de alumnos con notas mayores o iguales a 7:");
System.out.println(conta1);

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I

System.out.print("Cantidad de alumons con notas menores a 7:");


System.out.print(conta2);
}

2. Se ingresan un conjunto de n alturas de personas por teclado. Mostrar la altura


promedio de las personas.
import java.io.*;
public class EstructuraRepetitivaWhile6 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int n,x;
float altura,suma,promedio;
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Cuantas personas hay:");
n=Integer.parseInt(leerdigito.readLine());
x=1;
suma=0;
while (x<=n)
{
System.out.println("Ingrese la altura:");
altura=Float.parseFloat(leerdigito.readLine());
suma=suma + altura;
x=x + 1;
}
promedio=suma/n;
System.out.print("Altura promedio:");
System.out.print(promedio);
}
}
3. En una empresa trabajan n empleados cuyos sueldos oscilan entre $100 y
$500, realizar un programa que lea los sueldos que cobra cada empleado e
informe cuntos empleados cobran entre $100 y $300 y cuntos cobran ms de
$300. Adems el programa deber informar el importe que gasta la empresa en
sueldos al personal.
4.
import java.io.*;
public class EstructuraRepetitivaWhile7 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int n,x,conta1,conta2;
float sueldo,gastos;
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I
System.out.println("Cuantos empleados tiene la empresa:");
n=Integer.parseInt(leerdigito.readLine());
x=1;
conta1=0;
conta2=0;
gastos=0;
while (x<=n)
{
System.out.println("Ingrese el sueldo del empleado:");
sueldo=Integer.parseInt(leerdigito.readLine());
if (sueldo<=300)
{
conta1=conta1 + 1;
}
else
{
conta2=conta2 + 1;
}
gastos=gastos+sueldo;
x=x + 1;
}
System.out.print("Cantidad de empleados con sueldos entre 100 y 300:");
System.out.println(conta1);
System.out.print("Cantidad de empleados con sueldos mayor a 300:");
System.out.println(conta2);
System.out.print("Gastos total de la empresa en sueldos:");
System.out.println(gastos);
}
}
5. Realizar un programa que imprima 25 trminos de la serie 11 - 22 - 33 - 44,
etc. (No se ingresan valores por teclado)
6.
import java.io.IOException;
public class EstructuraRepetitivaWhile8 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int x,termino;
x=1;
termino=11;
while (x<=25)
{
System.out.print(termino);
System.out.print(" - ");
x=x + 1;
termino=termino +11;
}
}
}

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I
7. Mostrar los mltiplos de 8 hasta el valor 500. Debe aparecer en pantalla 8 - 16
- 24, etc.
8.
import java.io.IOException;
public class EstructuraRepetitivaWhile9 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int mult8;
mult8=8;
while (mult8<=500)
{
System.out.print(mult8);
System.out.print(" - ");
mult8=mult8 + 8;
}
}
}
9. Realizar un programa que permita cargar dos listas de 15 valores cada una.
Informar con un mensaje cul de las dos listas tiene un valor acumulado mayor
(mensajes "Lista 1 mayor", "Lista 2 mayor", "Listas iguales")
Tener en cuenta que puede haber dos o ms estructuras repetitivas en un
algoritmo.
import java.io.*;
public class EstructuraRepetitivaWhile10 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int valor,x,suma1,suma2;
x=1;
suma1=0;
suma2=0;
System.out.println("Primer lista");
while (x<=15)
{
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Ingrese valor:");
valor=Integer.parseInt(leerdigito.readLine());
suma1=suma1 + valor;
x=x + 1;
}
System.out.println("Segunda lista");
x=1;
while (x<=15)
{

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I
BufferedReader leerdigito2 = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Ingrese valor:");
valor=Integer.parseInt(leerdigito2.readLine());
suma2=suma2 + valor;
x=x + 1;
}
if (suma1>suma2)
{
System.out.print("Lista 1 mayor.");
}
else
{
if (suma2>suma1)
{
System.out.print("Lista2 mayor.");
}
else
{
System.out.print("Listas iguales.");
}
}
}
}
10. Desarrollar un programa que permita cargar n nmeros enteros y luego nos
informe cuntos valores fueron pares y cuntos impares.
Emplear el operador ?%? en la condicin de la estructura condicional:
if (valor%2==0) //Si el if da verdadero luego es par
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class EstructuraRepetitivaWhile11 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int n,x,valor,pares,impares;
x=1;
pares=0;
impares=0;
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Cuantos nmeros ingresar:");
n=Integer.parseInt(leerdigito.readLine());
while (x<=n)
{
System.out.println("Ingrese el valor:");

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I
valor=Integer.parseInt(leerdigito.readLine());
if (valor%2==0)
{
pares=pares + 1;
}
else
{
impares=impares + 1;
}
x=x + 1;
}
System.out.print("Cantadad de pares:");
System.out.println(pares);
System.out.print("Cantidad de impares:");
System.out.print(impares);
}
}

PROBLEMAS PROPUESTOS
Pgina 69
1. Confeccionar un programa que lea n pares de datos, cada par de
datos corresponde a la medida de la base y la altura de un
tringulo. El programa deber informar:
o De cada tringulo la medida de su base, su altura y su
superficie
o La cantidad de tringulos cuya superficie es mayor a 12.
import java.io.*;
public class EstructuraRepetitivaFor6 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int base,altura,superficie,cantidad,f,n;
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
cantidad=0;
System.out.println("Cuantos tringulos procesar:");
n=Integer.parseInt(leerdigito.readLine());
for(f=1;f<=n;f++)
{
System.out.println("Ingrese el valor de la base:");
base=Integer.parseInt(leerdigito.readLine());
System.out.println("Ingrese el valor de la altura:");
altura=Integer.parseInt(leerdigito.readLine());
superficie=base*altura/2;
System.out.print("La superficie es:");
System.out.println(superficie);

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I
if (superficie>12)
{
cantidad=cantidad+1;
}
}
System.out.print("La cantidad de tringulos con superficie superior a 12 son:");
System.out.print(cantidad);
}
}
2. Desarrollar un programa que solicite la carga de 10 nmeros e imprima la suma
de los ltimos 5 valores ingresados.
3.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class EstructuraRepetitivaFor7 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int f,valor,suma;
suma=0;
for(f=1;f<=10;f++)
{
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Ingrese un valor:");
valor=Integer.parseInt(leerdigito.readLine());
if (f>5)
{
suma=suma+valor;
}
}
System.out.print("La suma de los ltimos 5 valores es:");
System.out.print(suma);
}
}
4. Desarrollar un programa que muestre la tabla de multiplicar del 5 (del 5 al 50)
import java.io.IOException;
public class EstructuraRepetitivaFor8 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int f;
for(f=5;f<=50;f=f+5) {
System.out.print(f);
System.out.print("-");
}
}

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I
}
5. Confeccionar un programa que permita ingresar un valor del 1 al 10 y nos
muestre la tabla de multiplicar del mismo (los primeros 12 trminos) Ejemplo:
Si ingreso 3 deber aparecer en pantalla los valores 3, 6, 9, hasta el 36.
6.
import java.io.*;
public class EstructuraRepetitivaFor9 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int f,lado1,lado2,lado3,cant1,cant2,cant3,n;
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
cant1=0;
cant2=0;
cant3=0;
System.out.println("Ingrese la cantidad de tringulos:");
n=Integer.parseInt(leerdigito.readLine());
for(f=1;f<=n;f++)
{
System.out.println("Ingrese lado 1:");
lado1=Integer.parseInt(leerdigito.readLine());
System.out.println("Ingrese lado 2:");
lado2=Integer.parseInt(leerdigito.readLine());
System.out.println("Ingrese lado 3:");
lado3=Integer.parseInt(leerdigito.readLine());
if (lado1==lado2 && lado1==lado3)
{
System.out.println("Es un tringulo equilatero.");
cant1++;
}
else
{
if (lado1==lado2 || lado1==lado3 || lado2==lado3)
{
System.out.println("Es un tringulo issceles.");
cant2++;
}
else
{
cant3++;
System.out.println("Es un tringulo escaleno.");
}
}
}
System.out.print("Cantidad de tringulos equilateros:");
System.out.println(cant1);

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I
System.out.print("Cantidad de tringulos issceles:");
System.out.println(cant2);
System.out.print("Cantidad de tringulos escalenos:");
System.out.println(cant3);
if (cant1<cant2 && cant1<cant3)
{
System.out.print("Hay menor cantidad de tringulos equilateros.");
}
else
{
if (cant2<cant3)
{
System.out.print("Hay menor cantidad de tringulos issceles");
}
else
{
System.out.print("Hay menor cantidad de tringulos escalenos");
}
}
}
}
7. Realizar un programa que lea los lados de n tringulos, e informar:
a) De cada uno de ellos, qu tipo de tringulo es: equiltero (tres lados
iguales), issceles (dos lados iguales), o escaleno (ningn lado igual)
b) Cantidad de tringulos de cada tipo.
c) Tipo de tringulo que posee menor cantidad.
import java.io.*;
public class EstructuraRepetitivaFor10 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int n,f,x,y,cant1,cant2,cant3,cant4;
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
cant1=0;
cant2=0;
cant3=0;
cant4=0;
System.out.println("Cantidad de puntos:");
n=Integer.parseInt(leerdigito.readLine());
for(f=1;f<=n;f++)
{
System.out.println("Ingrese coordenada x:");
x=Integer.parseInt(leerdigito.readLine());
System.out.println("Ingrese coordenada y:");
y=Integer.parseInt(leerdigito.readLine());

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I

if (x>0 && y>0)


{
cant1++;
}
else
{
if (x<0 && y>0)
{
cant2++;
}
else
{
if (x<0 && y<0)
{
cant3++;
}
else
{
if (x>0 && y<0)
{
cant4++;
}
}
}
}
}
System.out.print("Cantidad
System.out.println(cant1);
System.out.print("Cantidad
System.out.println(cant2);
System.out.print("Cantidad
System.out.println(cant3);
System.out.print("Cantidad
System.out.println(cant4);
}

de puntos en el primer cuadrante:");


de puntos en el segundo cuadrante:");
de puntos en el tercer cuadrante:");
de puntos en el cuarto cuadrante:");

8. Escribir un programa que pida ingresar coordenadas (x,y) que representan


puntos en el plano. Informar cuntos puntos se han ingresado en el primer,
segundo, tercer y cuarto cuadrante. Al comenzar el programa se pide que se
ingrese la cantidad de puntos a procesar.
Se realiza la carga de 10 valores enteros por teclado. Se desea conocer:
a) La cantidad de valores ingresados negativos.
b) La cantidad de valores ingresados positivos.
c) La cantidad de mltiplos de 15.
d) El valor acumulado de los nmeros ingresados que son pares.
import java.io.*;

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I
public class EstructuraRepetitivaFor11 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int f,valor,negativos,positivos,mult15,sumapares;
negativos=0;
positivos=0;
mult15=0;
sumapares=0;
for(f=1;f<=10;f++)
{
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Ingrese valor:");
valor=Integer.parseInt(leerdigito.readLine());
if (valor<0)
{
negativos++;
}
else
{
if (valor>0)
{
positivos++;
}
}
if (valor%15==0)
{
mult15++;
}
if (valor%2==0)
{
sumapares=sumapares+valor;
}
}
System.out.print("Cantidad de valores negativos:");
System.out.println(negativos);
System.out.print("Cantidad de valores positivos:");
System.out.println(positivos);
System.out.print("Cantidad de valores mltiplos de 15:");
System.out.println(mult15);
System.out.print("Suma de los valores pares:");
System.out.println(sumapares);
}
}
9. Se cuenta con
Las edades de
Las edades de
Las edades de

la siguiente informacin:
50 estudiantes del turno maana.
60 estudiantes del turno tarde.
110 estudiantes del turno noche.

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I
Las edades de cada estudiante deben ingresarse por teclado.
a) Obtener el promedio de las edades de cada turno (tres promedios)
b) Imprimir dichos promedios (promedio de cada turno)
c) Mostrar por pantalla un mensaje que indique cul de los tres turnos tiene un
promedio de edades mayor.
import java.io.*;
public class EstructuraRepetitivaFor12 {
public static void main(String[] ar) throws NumberFormatException,
IOException
{
int f,edad,suma1,suma2,suma3,pro1,pro2,pro3;
BufferedReader leerdigito = new BufferedReader(new
InputStreamReader(System.in));
suma1=0;
suma2=0;
suma3=0;
for(f=1;f<=5;f++)
{
System.out.println("Ingrese edad:");
edad=Integer.parseInt(leerdigito.readLine());
suma1=suma1+edad;
}
pro1=suma1/50;
System.out.print("Promedio de edades del turno maana:");
System.out.println(pro1);
for(f=1;f<=5;f++)
{
System.out.println("Ingrese edad:");
edad=Integer.parseInt(leerdigito.readLine());
suma2=suma2+edad;
}
pro2=suma2/60;
System.out.print("Promedio de edades del turno tarde:");
System.out.println(pro2);
for(f=1;f<=5;f++)
{
System.out.println("Ingrese edad:");
edad=Integer.parseInt(leerdigito.readLine());
suma3=suma3+edad;
}
pro3=suma3/110;
System.out.print("Promedio de edades del turno noche:");
System.out.println(pro3);
if (pro1<pro2 && pro1<pro3) {
System.out.print("El turno maana tiene un promedio menor de edades.");
} else {
if (pro2<pro3) {
System.out.print("El turno tarde tiene un promedio menor de edades.");

ESCUELA DE CIENCIAS BSICAS TECNOLOGAS E INGENIERA


Programacin Orientada A Objetos
Cdigo 301403
2.015_I

} else {
System.out.print("El turno noche tiene un promedio menor de edades.");
}
}
}

También podría gustarte