Vous êtes sur la page 1sur 19

PROGRAMACION I

(EJERCICIOS DE LA INSTRUCCIN FOR)


1.- El Instituto Nacional de Estadstica dispone de la siguiente informacin
para todas las provincias del Ecuador:
-Cdigo y nombre de la provincia
-Nmero de empleados pblicos con ttulo universitario
-Nmero de empleados pblicos sin ttulo universitario
Obtener el nmero total de empleados pblicos con ttulo universitario, sin
ttulo universitario y de empleados pblicos.

package com.compunauta.aprendiendojava;
import java.io.*;
public class NOMBRE {
public static void main(String[] args) {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Hola, ingresa tu nombre");
String nombre;
nombre = br.readLine();}
System.out.println("Hola,"+nombre+"ten un buen dia");
}

package com.compunauta.aprendiendojava;
import java.io.*;
public class NOMBRE {
public static void main(String[] args) {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Hola, ingresa tu nombre");
String nombre;
Int num=0;
nombre = br.readLine();}
System.out.println("Hola,"+nombre+"ten un buen dia");
System.out.println("Hola,"+nombre+"ingresa tu edad");
num=Integer.parselnt(br.readLine());
}

import java.io.*;
public class EMPLEADOS {
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Hola, ingresa tu nombre");
String nombre;
nombre=br.readLine();
System.out.println(" Hola, " +nombre+ " ten un buen dia ");
System.exit(0);
}
}

import java.io.*;
public class Provincias {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int numero;
String provincia;
System.out.println("Hola, ingresa el nombre de la provincia");
provincia=(br.readLine());}
System.out.println(provincia+ "Ingrese el numero de empleados con titulo");
numero=Integer.parselnt(br.readLine());
System.out.println(provincia+ "Ingrese el numero de empleados sin titulo");
numero=Integer.parselnt(br.readLine());
System.out.println(provincia+ "empleados con titulo" +numero+" empleados
sin titulo"+numero+ );
}

Desplegar los n primeros nmeros

SERIE
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int numero,fibo1,fibo2,i;
do{

System.out.print("Introduce numero mayor que 1: ");


numero = sc.nextInt();
}while(numero<=1);
System.out.println("Los " + numero + " primeros trminos de la
serie de Fibonacci son:");
fibo1=1;
fibo2=1;
System.out.print(fibo1 + " ");
for(i=2;i<=numero;i++){
System.out.print(fibo2 + " ");
fibo2 = fibo1 + fibo2;
fibo1 = fibo2 - fibo1;
}
System.out.println();
}
}

Numeros primos
import java.io.*;
public class LOS20PRIMEROSPRIMOS {
public static void main(String[] args)throws NumberFormatException,
IOException {
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println ("ingrese la cantidad de numeros primos que
desea");
int n;
n=Integer.parseInt(br.readLine());
int i,total;
i=1;
total= i/n;
for (i=1;i<n;++i);
System.out.println ( "los n numeros primeros son " +total);

while (condicin)

Mientras se cumpla la condicin entre parntesis, se ejecuta el cdigo en el


interior de {} de manera infinita hasta.
do {

}
while(condicin) {

}
Mientras se cumpla la condicin entre parntesis, se ejecuta el cdigo en el
interior de {} de manera infinita hasta.

-----------------------------------------------------------------------------------------------------------------------Programa va a pedir un numero e imprime el numero q ingreso y preguntar


si desea continuar y as sucesivamente hasta que diga que no.
------------------------------------------------------------------------------------------------------------------------import java.util.Scanner;
public class Ingresenumero {
public static void main(String[] args) {
Scanner leer=new Scanner(System.in);
int n,a,b,c,f;
a=1;
b=2;
System.out.println("Ingrese un numero");
n=leer.nextInt();
System.out.println("Usted ingreso el numero " +n );
System.out.println("Desea ingresar otro numero si=1 o no=2");
c=leer.nextInt();
while(c==a)
{
System.out.println("Ingrese un numero");
f=leer.nextInt();
System.out.println("Usted ingreso el numero " +f );
System.out.println("Desea ingresar otro numero si=1 o no=2");
c=leer.nextInt();
if (c==b)
System.out.println("Fin del proceso");
}
}

--------------------------------------------------------------------------------------------------------------------Leer: Cdigo del empleado, nombre del empleado y sueldo.


Calcular y desplegar el aumento, si el sueldo es menor o igual a 500, el
aumento es del 10%,
Caso contrario es de 5%, Imprimir el sueldo antiguo y el nuevo sueldo.
Repetir el proceso hasta que el cdigo sea menor o igual a 0.

import java.io.*;
public class EmpleadoSueldo {
public static void main(String[] args) throws NumberFormatException,
IOException{
BufferedReader Empleado=new BufferedReader(new
InputStreamReader(System.in));
int c,s,d;
String nombre;
c=0;
s=0;
d=0;
System.out.println("Ingrese el codigo del empleado");
c=Integer.parseInt(Empleado.readLine());
System.out.println (" ");
System.out.println("Ingrese el nombre del empleado");
nombre=Empleado.readLine();
System.out.println (" ");
System.out.println("Ingrese el sueldo del empleado");
s=Integer.parseInt(Empleado.readLine());
System.out.println (" ");
}
}

import java.io.*;
public class Empleado {
public static void main(String[] args) throws NumberFormatException,
IOException {
BufferedReader Empleado=new BufferedReader(new
InputStreamReader(System.in));
String nom;
double j,s,a;
int i=1;
while(i==1) {
System.out.println("Ingrese el codigo del empleado");

j=Double.parseDouble(Empleado.readLine());
System.out.println("Ingrese el nombre del empleado");
nom=Empleado.readLine();
System.out.println("Ingrese el sueldo del empleado");
s=Double.parseDouble(Empleado.readLine());
if(s>500)
a=s+s*(0.10);
else
a=s+s*(0.05);
System.out.println("El nuevo sueldo del empleado es: "+a);
System.out.println("Desea ingresar otro empleado: si=1 /

no=0");

i=Integer.parseInt(Empleado.readLine());
if(i==0)
i=0;
}
}
}

import java.io.*;
public class Raiz {
public static void main(String[] args) throws NumberFormatException,
IOException {
BufferedReader Raiz=new BufferedReader(new
InputStreamReader(System.in));
double a=0;
int i,j,k,b,c,d,e,l=1;
while (l==1){
System.out.println("Ingrese el valor entero de x ");
i=Integer.parseInt(Raiz.readLine());
System.out.println("Ingrese el valor entero de y ");
j=Integer.parseInt(Raiz.readLine());
System.out.println("Ingrese el valor entero de z ");
k=Integer.parseInt(Raiz.readLine());
b=(int) Math.pow(i,2);
c=(int) Math.pow(j,2);
d=(int) Math.pow(k,2);
e=b+c+d;
l=e;
a=Math.sqrt(e);
System.out.println("La raiz cuadrada de la suma de los 3
numeros al cuadrado es: "+a);

if (l==0);
else
l=1;

}
}
}

import java.io.*;
public class MenuNumeros {
public static void main(String[] args) throws NumberFormatException,
IOException{
BufferedReader Br=new BufferedReader(new
InputStreamReader(System.in));
double d=0,b=0,c=0;
int a;
System.out.println("Este programa realiza las 4 operaciones
fundamentales");

System.out.println("Ingrese el primer numero");


b=Double.parseDouble(Br.readLine());
System.out.println("Ingrese el segundo numero");
c=Double.parseDouble(Br.readLine());
System.out.println("Que operacion desea realizar");
System.out.println("1.-Sumar");
System.out.println("2.-Restar");
System.out.println("3.-Multiplicar");
System.out.println("4.-Dividir");
a=Integer.parseInt(Br.readLine());
switch (a){
case 1:
d=b+c;
break;
case 2:
d=b-c;
break;
case 3:
d=b*c;
break;
case 4:
d=b/c;
break;

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

Deber del club campestre

import java.io.*;
public class ClubDelCampo {
public static void main(String[] args) throws IOException {
BufferedReader Br=new BufferedReader(new
InputStreamReader(System.in));
String nom;
int a,b,c,d,e,f,g,h,i,j,k=0,x=0,t,s=1;
double y=0;
int l=2014;
while (s==1){
System.out.println("Bienvenido al sistema de socios del Club Del
Campo");

System.out.println("Este sistema calcula los beneficios de los


socios por los 50 aos de nuestro aniversario");
System.out.println("Ingrese el nombre del socio");
nom=Br.readLine();
System.out.println("Ingrese el codigo del socio");
h=Integer.parseInt(Br.readLine());
System.out.println("Ingrese el ao en el que se hizo socio");
i=Integer.parseInt(Br.readLine());
t=l-i;
if(t<=10)
k=5;
else
if(t<=20)
if(t>10)
k=25;
if(t<=30)

if(t>20)
k=50;
if(t<=40)
if(t>30)
k=100;
if(t<=50)
if(t>40)
k=150;
if(t>50)
k=200;
System.out.println("Ingrese la
categoria en la que se encuentra el socio segun su ao de afiliacion");

1968 BONO DE 30%)");


1973 BONO DE 25%)");
1978 BONO DE 20%)");
2003 BONO DE 15%)");
2008 BONO DE 10%)");
2013 BONO DE 5%)");

System.out.println("1.- A(1964System.out.println("2.-B(1969System.out.println("3.-C(1974System.out.println("4.-D(1979System.out.println("5.-E(2004System.out.println("6.-F(2009System.out.println("7.-G(2014-

BONO DE 0%)");
x=Integer.parseInt(Br.readLine());

switch (x){
case 1:
y=k+(k*0.30);
break;
case 2:
y=k+(k*0.25);
break;
case 3:
y=k+(k*0.20);
break;
case 4:
y=k+(k*0.15);
break;
case 5:
y=k+(k*0.10);
break;
case 6:
y=k+(k*0.5);
break;
case 7:
y=k;
break;
}

+h+ " afiliado "

System.out.println("El bono del socio " +nom+ " con codigo # "

+ " en el ao "+i+" ubicado en la categoria "+x+"


recibe el bono de:$"+y);
System.out.println("Desea calcular el bono de otro socio si=1 /
no=0" );
s=Integer.parseInt(Br.readLine());
if (s==1)
s=1;
}
}
}

System.out.println("GRACIAS POR USAR EL SISTEMA" );

import java.io.*;
public class Vector {
public static void main(String[] args) throws IOException{
BufferedReader Br=new BufferedReader(new
InputStreamReader(System.in));
int nElementos;
int[]m = new int[3];
m[0]=1;
m[1]=2;
m[2]=3;

System.out.println("Primer elemento del vector m: "+m[0]);


System.out.println("Segundo elemento del vector m: "+m[1]);
System.out.println("Tercer elemento del vector m: "+m[2]);

import java.io.*;
public class Numeros {
public static void main(String[] args) throws IOException {
BufferedReader s=new BufferedReader(new InputStreamReader(System.in));
int A[],i,n;
System.out.print("Ingrese la cantidad de numeros del cual desea el vector: ");
n = Integer.parseInt(s.readLine());
A = new int [n];
for(i=0;i<n;i++)
{
System.out.print("Ingrese un numero: ");
A[i] = Integer.parseInt(s.readLine());
}
System.out.println("el vector es");
for(i=0;i<n;i++)
{
System.out.println(A[i]);
}
}
}

import java.io.*;
public class Vector1 {
static BufferedReader br = new BufferedReader(new InputStreamReader
(System.in));
public static void main(String[] args) throws IOException{
int x;
System.out.println("INGRESE LA CANTIDAD DE ELEMENTOS
DEL VECTOR");
x=Integer.parseInt(br.readLine());
int m[]=new int[x];
System.out.println("Ingrese los elementos");
for(int i=0;i<x;i++){
System.out.print(" a[" + i + "] =");
m[i]=Integer.parseInt(br.readLine());
}
System.out.println("El vector es : ");
for(int i=0;i<x;i++){
System.out.print(" " + m[i]);
}
for (int i=1;i<x;i++){
for(int j=0;j<i;j++){
if(m[i]<m[j]){
int B;
B=m[j];
m[j]=m[i];
m[i]=B;
}
}
}
System.out.println("\nEl vector ordenado es : ");
for(int i=0;i<x;i++){
System.out.print(" " + m[i]);
}
}
}

import java.io.*;
public class Mayor {
private int arreglo[]; // Atributo de la clase. Arreglo de tipo INT
/* Constructor sin paramentros. Lo que hace es establecer el tamao del
* arreglo en 20 elementos y cargarlo con numeros del 0 al 10 generados
* al azar.
*/
public Mayor()

{
arreglo = new int[20];
for(int i=0; i<arreglo.length; i++)
{
arreglo[i] = (int)(Math.random()*11);
System.out.println(arreglo[i]);
}
}
/* Metodo calcularMenor(): Genera una variable local y la inicializa con
* el valor del primer elemento del arreglo. Despues compara ese valor contra
* todos los elementos del arreglo. Si alguno es MENOR que el actual, entonces
* almacena ese valor en la variable resultado. Al final devuelve el valor
* del MENOR elemento del arreglo
*/
public int calcularMenor()
{
int resultado = arreglo[0];
for(int i=0; i<arreglo.length; i++)
{
if(arreglo[i] < resultado)
{
resultado = arreglo[i];
}
}
return resultado;
}
/* Metodo calcularMayor(): Genera una variable local y la inicializa con
* el valor del primer elemento del arreglo. Despues compara ese valor contra
* todos los elementos del arreglo. Si alguno es MAYOR que el actual, entonces
* almacena ese valor en la variable resultado. Al final devuelve el valor
* del MAYOR elemento del arreglo
*/
public int calcularMayor()
{
int resultado = arreglo[0];
for(int i=0; i<arreglo.length; i++)
{
if(arreglo[i] > resultado)
{
resultado = arreglo[i];
}
}
return resultado;
}
/* Metodo calcularPromedio(): Genera una variable local de tipo float llamada
* "resultado".Luego recorre el arreglo y acumula dentro de la variable el
* valor de todos los elementos del arreglo. Una vez que termino con todo el
* arreglo, divide la suma total de todos los valores por la cantidad de
* elementos que tiene el arreglo.
*/
public double calcularPromedio()
{
double resultado = 0;
int cantidad_numeros = 0;
for(int i=0; i<arreglo.length; i++)
{
resultado += arreglo[i];

cantidad_numeros ++;
}
resultado = (resultado / cantidad_numeros);
return resultado;
}
}

Meses del Ao
import java.io.*;
public class Meses {
public static void main(String[] args){
BufferedReader br = new BufferedReader(new InputStreamReader
(System.in));
String

Enero,Febrero,Marzo,Abril,Mayo,Junio,Julio,Agosto,Septiembre,Octubre,Noviembre,Di
ciembre;
System.out.println(" A continuacion el programa muestra los meses
del ao y sus respectivos numeros de dias ");
String x[]=new String[12];
x[0]="Enero";
x[1]="Febrero";
x[2]="Marzo";
x[3]="Abril";
x[4]="Mayo";
x[5]="Junio";
x[6]="Julio";
x[7]="Agosto";
x[8]="Septiembre";
x[9]="Octubre";
x[10]="Noviembre";
x[11]="Diciembre";
int y[]=new int[12];
y[0]=31;
y[1]=28;
y[2]=31;
y[3]=30;
y[4]=31;
y[5]=30;
y[6]=31;
y[7]=31;
y[8]=30;
y[9]=31;
y[10]=30;
y[11]=31;
for(int i=0;i<12;i++)
System.out.println ( "El mes " +x[i]+ " tiene " +y[i]+ " dias ");

Matriz

import java.io.*;
public class Matriz {
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader (new
InputStreamReader(System.in));
int c=5,a=1;
int [][] numM=new int [c][c];
for(int i=0;i<c;i++){
for(int j=0;j<c;j++){
numM[i][j]=a;
a=a+1;
}

}
System.out.println("La matriz es:");
for(int i=0;i<c;i++){
for(int j=0;j<c;j++){
System.out.print(numM[i][j]+"\t");
}
System.out.println(" ");

}
}

Matriz diagonal principal


import java.io.*;
public class Diagona {
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader (new
InputStreamReader(System.in));
int c=5,a=1;
int [][] numM=new int [c][c];
for(int i=0;i<c;i++){
for(int j=0;j<c;j++){
numM[i][j]=a;

if (i==j+1)
a=1;
else{
a=0;
}
}

}
System.out.println("La matriz es:");
for(int i=0;i<c;i++){
for(int j=0;j<c;j++){
System.out.print(numM[i][j]+"\t");
}
System.out.println(" ");

}
}

import java.io.*;
public class DiagonalSecundaria {
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader (new
InputStreamReader(System.in));
int c=0,a=1;
System.out.println("Ingrese el numero de la matriz:");
c= Integer.parseInt(br.readLine());
int [][] numM=new int [c][c];
for(int i=0;i<c;i++){
for(int j=0;j<c;j++){
numM[i][j]=a;
if (i==j+1)
a=1;
else{
a=0;
}

}
System.out.println("La matriz es:");
for(int i=0;i<c;i++){
for(int j=0;j<c;j++){
System.out.print(numM[i][j]+"\t");
}
System.out.println(" ");

}
}

import java.io.*;
public class der {

static String nombre;


static int edad;
static void leer() throws IOException{
BufferedReader b=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("INGRESE EL NOMBRE ");
nombre=b.readLine();
System.out.println("INGRESE LA EDAD ");
edad=Integer.parseInt(b.readLine());

}
static void desplegar() throws IOException{
System.out.println("EL NOMBRE ES: "+nombre);
System.out.println("LA EDAD ES: "+edad);
}
public static void main(String[] args) throws IOException {
leer();
desplegar();
}

import java.io.*;
public class UsuariosBanco {
static
static
static
static

String nombre;
double montoini,montofin,deudaact;
double cuota1,cuota2,cuota3,cuota4,cuota5,aporte;
int a=1,c=0,n;

static void leer() throws IOException{


BufferedReader b=new BufferedReader(new
InputStreamReader(System.in));

CALCULAR ");

System.out.println("INGRESE EL NUMERO DE PRESTAMISTAS A


n=Integer.parseInt(b.readLine());
System.out.println("INGRESE EL NOMBRE DEL PRESTAMISTA ");
nombre=b.readLine();
System.out.println("INGRESE EL MONTO DEL PRESTAMO ");
montoini=Double.parseDouble(b.readLine());
System.out.println("INGRESE LAS 5 PRIMERAS CUOTAS DEL

PRESTAMO ");

cuota1=Double.parseDouble(b.readLine());
double m[]=new double[double cuota1];
for(int i=0;i<5;i++);

String x[]=new String[12];


x[0]="USUARIO";
x[1]="PRESTAMO";
x[2]="C1";
x[3]="C2";

x[4]="C3";
x[5]="C4";
x[6]="C5";
x[7]="TOTAL PAGADO";
x[8]="TOTAL DEUDA";
int y[]=new int[12];
y[0]=31;
y[1]=28;
y[2]=31;
y[3]=30;
y[4]=31;
y[5]=30;
y[6]=31;
y[7]=31;

montofin=montoini+(montoini*0.15);
aporte=cuota1+cuota2+cuota3+cuota4+cuota5;
deudaact=(montofin-aporte);
}
static void desplegar() throws IOException{
System.out.println(
);
}
public static void main(String[] args) throws IOException {
leer();
desplegar();
}
}

import java.io.*;
public class met1 {
// Mtodo que calcula y devuelve la suma y recibe 2 valores
(parmetros)
static double suma(double x ,double y){
double resp;
resp= x+y;
return resp;
}
// Mtodo que devuelve la resta y recibe 2 valores
(parmetros)
static double resta(double x ,double y){
return (x-y);
}
// Mtodo que devuelve la divisin y recibe 2 valores
(parmetros)

static double division(double x ,double y){


return ((double)x/y);
}
public static void main(String[] args) throws
NumberFormatException, IOException {
BufferedReader b=new BufferedReader (new
InputStreamReader(System.in));
double a,w,z,n;
System.out.println(" PROGRAMA QUE SUMA, RESTA Y DIVIDE
DOS NMEROS INGRESADOS POR TECLADO ");
System.out.print("Ingrese el primer nmero: ");
a = Integer.parseInt(b.readLine());
System.out.println("");
System.out.print("Ingrese el segundo nmero: ");
n = Integer.parseInt(b.readLine());
System.out.println("");
w=suma(a,n);
// lamma al metodo suma y su
resultado lo asigna a w
System.out.println("La suma es: "+w);
w=resta(a,n);
// lamma al metodo resta y su
resultado lo asigna a w
System.out.println("La resta es: "+w);
w=division(a,n);
// lamma al metodo division y su
resultado lo asigna a w
System.out.println("La division es: "+w);
System.out.println(" FIN DE PROGRAMA ");
import java.io.*;
public class der {
public static void main(String[] args) throws IOException {
BufferedReader matriz=new BufferedReader(new
InputStreamReader(System.in));
int n=0;
System.out.println("INGRESE EL TAMAO DE LA MATRIZ nxn ");
n=Integer.parseInt(matriz.readLine());
int mata[][] =new int[n][n];
int matb[][] =new int[n][n];
int matc[][] =new int[n][n];
int matd[][] =new int[n][n];
System.out.println("INGRESE LOS NUMEROS QUE COMPONEN A
LA PRIMERA MATRIZ A ");
for(int i=0;i<n;i++){
for(int j=0; j<n;j++ ){
System.out.print("Escribir valor " + i + " ,
" + j + " : ");
mata[i][j]=Integer.parseInt(matriz.readLine());
}
}
System.out.println("LA MATRIZ A ES:" );
for(int i=0;i<n;i++){
for(int j=0; j<n;j++ ){
System.out.print(+mata[i][j]+"\t" );
}
System.out.println("");

}
System.out.println("INGRESE LOS NUMEROS QUE COMPONEN A
LA SEGUNDA MATRIZ B ");
for(int i=0;i<n;i++){
for(int j=0; j<n;j++ ){
System.out.print("Escribir valor " + i + " ,
" + j + " : ");
matb[i][j]=Integer.parseInt(matriz.readLine());
}
}
System.out.println("LA MATRIZ B ES:" );
for(int i=0;i<n;i++){
for(int j=0; j<n;j++ ){
System.out.print(+mata[i][j]+"\t" );
}
System.out.println("");
}
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
matc [i][j]= mata[i][j]+matb[i][j];
}
}
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
matc [i][j]= mata[i][j]-matb[i][j];
}
}
System.out.println("La suma de la matriz A+B=C");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print (+matc[i][j]+"\t");
}
System.out.println("");
}
System.out.println("La resta de la matriz A-B=D");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print (+matd[i][j]+"\t");
}
System.out.println("");
}
}
}

Vous aimerez peut-être aussi