Programa en java
YeusLyApuntes18 de Mayo de 2022
738 Palabras (3 Páginas)90 Visitas
[pic 1]
UNIVERSIDAD NACIONAL MAYOR DE SAN MARCOS
ÁREA DE INGENIERÍA
FACULTAD DE INGENIERÍA DE SISTEMAS E INFORMÁTICA
EP INGENIERÍA DE SISTEMAS
[pic 2]
Tarea asincrónica 2
Curso:
Estructura de datos
Profesor:
Cabrera Diaz, Javier Elmer
Integrantes:
Manrique Pérez Renzo Jheus 20200018
Sección:
1
2022-1
[pic 3][pic 4][pic 5][pic 6]
Bases de la tarea
Ingresar un arreglo por teclado para luego proceder a digitar que valor del arreglo se va a eliminar. Ordenarlo en forma ascendente y luego mostrar el nuevo arreglo.
Programa
package semana1_edtarea;
import java.util.Scanner;
public class ElimPosArreglo {
public static void main(String[] args) {
Scanner teclado = new Scanner(System.in);
int t, arreglo[], aux, ElimNum, ElimPos = 0;
//Tamaño
System.out.print("Digite el tamaño del arreglo: ");
t = teclado.nextInt();
arreglo = new int[t];
//Llenado
System.out.println("\nDigite un numero para la posicion: ");
for(int i=0; i<t; i++){
System.out.print("["+i+"] ");
arreglo[i] = teclado.nextInt();
}
//Ordenado
for(int i=0; i<t-1; i++){
for(int j=0; j<t-1; j++){
if(arreglo[j] > arreglo[j+1]){
aux = arreglo[j];
arreglo[j] = arreglo[j+1];
arreglo[j+1] = aux;
}
}
}
//Eliminado
System.out.print("\nDigite el numero a eliminar: ");
ElimNum = teclado.nextInt();
for(int i=0; i<t; i++){
if(ElimNum == arreglo[i]){
ElimPos = i;
}
}
for(int i=ElimPos; i<t-1; i++){
arreglo[i] = arreglo[i+1];
}
//Mostrado
System.out.println("\nEL nuevo arreglo es: ");
for(int i=0; i<t-1; i++){
System.out.println("["+i+"] "+arreglo[i]);
}
}
}
Ejecución del programa
[pic 7]
[pic 8][pic 9][pic 10]
...