Está en la página 1de 8

Ao De La Promocin De La Industria Responsable y

Del Compromiso Climtico

Tema: Tarea 4 Programaciones


Especialidad: Ingeniera De Sistemas

Asignatura: Tcnicas De Programacin

Docente: Csar Augusto Cspedes Cornejo

Estudiante: Oviedo Ortiz Ronaldo

Ciclo: IIciclo

1. Programa para ingresar n nombres en un arreglo y


luego reportarlos en orden alfabtico.
BufferedReader dato=new BufferedReader (new
InputStreamReader (System.in));
int nmb, i, j;
String nombres [],aux;
do{
System.out.print ("Ingrese Cantidad De Nombres :");
nmb = Integer.parseInt (dato.readLine ());
} while (nmb<=0);
nombres = new String[nmb];
for (i=0; i<nmb; i++) {
System.out.print ("Nombre["+i+"]: ");
nombres[i] = dato.readLine ();
}
System.out.println ("Nombres Ingresados:");
for (i=0; i<nmb;i++)
System.out.println ("Nombre["+i+"]: "+nombres[i]);
for (i=0; i<nmb-1; i++)
for (j=i+1; j<nmb; j++)
if (nombres[i].compareToIgnoreCase (nombres[j])>0){
aux=nombres[i];
nombres[i]=nombres[j];
nombres[j]=aux;
}
System.out.println ("nombres Orden Alfabetico");
for(i=0; i<nmb;i++)
System.out.println ("Nombre["+i+"]: " + nombres[i]);
}
}

EJECUTAMOS EL PROGRAMA PARA EL RESULTADO FINAL

2.Programa para ingresar n nmeros en un arreglo y luego


ingresar un nmero y si este se encuentra eliminarlo en caso
contrario reportar dato no se encuentra
BufferedReader dato=new BufferedReader (new
InputStreamReader(System.in));
int x[], nmr;
int n, i, p ;

do{
System.out.println ("Cantidad Elementos A Arreglo: ");
nmr=Integer.parseInt (dato.readLine());
} while (nmr<=0);
x = new int[nmr];
for (i=0; i<nmr;i++){
System.out.print ("===>["+i+"]: ");
x[i]= Integer.parseInt (dato.readLine());
}
System.out.println ("Datos Ingresados ");
for(i=0; i<nmr;i++)
System.out.println("===>["+i+"]: "+x[i]);
System.out.println ("Buscar Numero: ");
nmr = Integer.parseInt (dato.readLine ());
p = -1;
for(i=0;i<nmr ;i++)
if(x[i] == nmr){
p=i;
break;
}
if(p!=-1){
for(i=p;i<nmr-1;i++)
x[i]=x[i+1];
nmr = nmr-1;
System.out.println ("Nuevo Arreglo:");

for(i=0; i<nmr;i++)
System.out.println("x["+i+"]: "+x[i]);
}
else
System.out.println ("El numero no se encuentra en el arreglo:");
}

EJECUTAMOS EL PROGRAMA PARA EL RESULTADO FINAL

3.Ingresar los nombres y las notas de n alumnos y reportar la


lista en orden alfabtico y en orden de mrito
BufferedReader dato=new BufferedReader (new
InputStreamReader(System.in));
String nombres[],auxNom;
int num,i,j,notas[],auxNota;
do{
System.out.print("Numero de Alumnos :");
num=Integer.parseInt(dato.readLine());
}while(num<=0);
nombres=new String[num];
notas=new int[num];
for(i=0; i<num;i++){
System.out.print("Nombre["+(i+1)+"]: ");
nombres[i] = dato.readLine();
System.out.print("Nota["+(i+1)+"]:");
notas[i]=Integer.parseInt(dato.readLine());

}
for(i=0;i<num-1;i++)
for(j=i+1;j<num;j++)
if(nombres[i].compareToIgnoreCase(nombres[j])>0){
auxNom=nombres[i];
nombres[i]=nombres[j];
nombres[j]=auxNom;
auxNota=notas[i];
notas[i]=notas[j];
notas[j]=auxNota;
}
System.out.println("Lista Orden Alfabetico");
for(i=0; i<num;i++)
System.out.println(nombres[i]+"\t\t "+notas[i]);
for(i=0;i<num-1;i++)
for(j=i+1;j<num;j++)
if(notas[i]<notas[j]){
auxNom=nombres[i];
nombres[i]=nombres[j];
nombres[j]=auxNom;
auxNota=notas[i];
notas[i]=notas[j];
notas[j]=auxNota;
}
System.out.println("Lista Orden de Merito");

for(i=0; i<num;i++)
System.out.println(nombres[i]+"\t\t "+notas[i]);

EJECUTAMOS EL PROGRAMA PARA EL RESULTADO FINAL

También podría gustarte