Documentos de Académico
Documentos de Profesional
Documentos de Cultura
//
for (pos = 0; pos < num.length; pos++) {
try {
elem = Integer.parseInt(JOptionPane.showInputDialog(null,
"ingrese el numero: "));
num[pos] = elem;
ban = true;
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "ingrese el dato de tipo
numerico:");
pos--;
ban = false;
}
}
break;
// }while
//(ban==false);
case 2:
imp = "";
for (pos = 0; pos < num.length; pos++) {
imp = imp + num[pos] + "\n";
}
JOptionPane.showMessageDialog(null, "el arreglo ordenado en
forma ascendente es: " + "\n" + imp);
break;
case 3:
//buscar elemento en el arreglo
elembuq = Integer.parseInt(JOptionPane.showInputDialog(null,
"ingrese el numero a buscar"));
}
//imprimir
break;
case 5:
//Actualizar
imp = "";
elembuq = Integer.parseInt(JOptionPane.showInputDialog(null,
"ingrese el numero a buscar: "));
numactualizar =
Integer.parseInt(JOptionPane.showInputDialog(null, "ingrese el valor a actulizar
es:"));
for (pos = 0; pos < num.length; pos++) {
if (num[pos] == elembuq) {
num[pos] = numactualizar;
}
//imprimir
}
for (pos = 0; pos < num.length; pos++) {
imp = imp + num[pos] + "\n";
}
JOptionPane.showMessageDialog(null, "el arreglo ordenado en
forma ascendente es: " + "\n" + imp);
///oredenar cada uno de las opciones del arreglo casi 1 debe ir
todo lo del llenado y el arreglo tamao,
break;
case 6:
System.exit(0);
default:
JOptionPane.showMessageDialog(null, "Eror.ingrese u dato
correcto");
}
} while (opmenu == true)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&
import javax.swing.JOptionPane;
public class LeerVectores {
private int i,n;
private String Print,Valor;
public void VectorEntero()
{
do{
break;//fin caso 1
case 2:
if (num.length >= 1) {
case 3:
if (num.length > 1) {
Print= "Numero de Registros " + num.length + "\n\n";
for (i = 0; i <= (num.length - 1); i++) {
Print = Print + "Posicin " + (i + 1) + " : " + num[i] + "\n";
}
Valor = JOptionPane.showInputDialog(null, "Cual es la
posicin del Registro que desea Eliminar. " + Print, "Eliminar datos vel vector",
JOptionPane.QUESTION_MESSAGE);
elemento1 = Integer.parseInt(Valor) - 1;
if (elemento1 <= num.length - 1) {
for (i = elemento1; i <= (num.length - 1); i++) {
if (i != num.length - 1) {
num_tem[i] = num[i + 1];
}
}
num= new int[num_tem.length - 1];
Print = "Numero de Registros " + num.length + "\n\n";
for (i = 0; i <= (num.length - 1); i++) {
num[i] = num_tem[i];
Print = Print + "Posicin " + (i + 1) + ": " + num[i] +
"\n";
}
num_tem = new int[num.length];
for (i = 0; i <= (num.length - 1); i++) {
num_tem[i] = num[i];
}
if (num.length >= 1) {
for (i = 0; i <= (num.length - 1); i++) {
for (n = 0; n <= (num.length - 2); n++) {
elemento1 = num[n + 1];
elemento2 = num[n];
if (elemento1 < elemento2) {
num[n] = elemento1;
num[n + 1] = elemento2;
}
}
}
Print = "Numero de Registros " + num.length + "\n\n";
for (i = 0; i <= (num.length - 1); i++) {
Print = Print + "Posicin " + (i + 1) + ": " + num[i] + "\n";
}
JOptionPane.showMessageDialog(null, " " + Print, "Mostrar
datos del vector", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "No hay Registros en El
arreglo", "Mostrar datos del vector", JOptionPane.ERROR_MESSAGE);
}
break;
case 5:
System.exit (0);
break;
}//fin swic
}while(Integer.parseInt (opcion)!=6);
}//fin metodo
String opcion;
int dat;
double elemen1 = 0, elemen2 = 0;
do{
opcion=JOptionPane.showInputDialog ("Menu Vectores de tipo
Real\n 1. Ingresar \n 2. Modificar\n 3. Eliminar\n 4. Mostrar\n 5. Salir");
dat=Integer.parseInt (opcion);
switch(dat)
{
case 1:
if(dato.length==0)
{dato=new double [1];
dato[0]=Integer.parseInt (JOptionPane.showInputDialog
("Ingrese el valor " ));}
else if(dato.length>0)
{dato_t=new double [dato.length+1];
for(int i=0;i<=(dato.length-1);i++)
{dato_t[i]=dato[i];}
dato_t[dato_t.length-1]=Integer.parseInt
(JOptionPane.showInputDialog (null,"ingrese el valor " ));
dato=new double [dato_t.length];
for(int i=0;i<=(dato_t.length-1);i++)
{dato[i]=dato_t[i];}
}//fin else
break;
case 2:
if (dato.length >= 1) {
Print= "Numero de Registros " + dato.length + "\n\n";
for (i = 0; i <= (dato.length - 1); i++) {
Print = Print + "Posicin " + (i + 1) + ": " + dato[i] + "\n";
}
Valor = JOptionPane.showInputDialog(null, "Cual es la
posicin del Registro que desea Modificar. " + Print, "Modificar valor del
vector", JOptionPane.QUESTION_MESSAGE);
if (Integer.parseInt(Valor) <= dato.length) {
n = Integer.parseInt(Valor);
Valor = JOptionPane.showInputDialog(null, "Nuevo Valor de
la Posicin: " + n, "Modificar valor del vector",
JOptionPane.QUESTION_MESSAGE);
dato[n - 1] = Integer.parseInt(Valor);
Print = "Numero de Registros " + dato.length + "\n\n";
for (i = 0; i <= (dato.length - 1); i++) {
Print= Print + "Posicin " + (i + 1) + ": " + dato[i] + "\n";
}
JOptionPane.showMessageDialog(null, "Registro Modificado
Exitosamente! " +Print, "Moficicar valor del vector",
JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "La Posicin
Seleccionada No existe en este vector!.", "Modificar valor del vector",
JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(null, "No hay Registros para
Modificar.", "Modificar valor del vector", JOptionPane.ERROR_MESSAGE);
}
break;
case 3:
if (dato.length > 1) {
Print= "Numero de Registros " + dato.length + "\n\n";
for (i = 0; i <= (dato.length - 1); i++) {
Print = Print + "Posicin " + (i + 1) + " : " + dato[i] + "\n";}
Valor= JOptionPane.showInputDialog(null, "Cual es la posicin
del Registro que desea Eliminar. " + Print, "Eliminar datos vel vector",
JOptionPane.QUESTION_MESSAGE);
elemen1 = Double.parseDouble (Valor)-1;
int x;
x=(int)elemen1;
if (elemen1 <= dato.length - 1) {
for (i = x; i <= (dato.length - 1); i++) {
if (i != dato.length - 1) {
dato_t[i] = dato[i + 1];}}
dato= new double [dato_t.length - 1];
Print = "Numero de Registros " + dato.length + "\n\n";
for (i = 0; i <= (dato.length - 1); i++) {
dato[i] = dato_t[i];
elemen2 = dato[n];
if (elemen1 < elemen2) {
dato[n] = elemen1;
dato[n + 1] = elemen2;
}
}
}
Print = "Numero de Registros " + dato.length + "\n\n";
for (i = 0; i <= (dato.length - 1); i++) {
Print = Print + "Posicin " + (i + 1) + ": " + dato[i] + "\n";
}
JOptionPane.showMessageDialog(null, " " + Print, "Mostrar
datos del vector", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "No hay Registros en El
arreglo", "Mostrar datos del vector", JOptionPane.ERROR_MESSAGE);
}
break;
case 5:
System.exit (0);
break;
}while(Integer.parseInt (opcion)!=6);
}//fin metodo
{texto[i]=texto_t[i];}
} //fin else
break;
case 2:
if (texto.length >= 1) {
Print= "Numero de Registros " + texto.length + "\n\n";
for (i = 0; i <= (texto.length - 1); i++) {
Print = Print + "Posicin " + (i + 1) + ": " + texto[i] + "\n";
}
Valor = JOptionPane.showInputDialog(null, "Cual es la
posicin del Registro que desea Modificar. " + Print, "Modificar valor del
vector", JOptionPane.QUESTION_MESSAGE);
if (Integer.parseInt(Valor) <= texto.length) {
n = Integer.parseInt(Valor);
texto[n - 1] = JOptionPane.showInputDialog(null,"Nuevo
dato de la Posicin: " + n, "Modificar valor del vector",
JOptionPane.QUESTION_MESSAGE);
Print = "Numero de Registros " + texto.length + "\n\n";
for (i = 0; i <= (texto.length - 1); i++) {
Print= Print + "Posicin " + (i + 1) + ": " + texto[i] +
"\n";
}
JOptionPane.showMessageDialog(null, "Registro Modificado
Exitosamente! " +Print, "Moficicar valor del vector",
JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "La Posicin
Seleccionada No existe en este vector!.", "Modificar valor del vector",
JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(null, "No hay Registros para
Modificar.", "Modificar valor del vector", JOptionPane.ERROR_MESSAGE);
}
break;
case 3:
if (texto.length > 1) {
Print= "Numero de Registros " + texto.length + "\n\n";
for (i = 0; i <= (texto.length - 1); i++) {
Print = Print + "Posicin " + (i + 1) + " : " + texto[i] +
"\n";}
Valor= JOptionPane.showInputDialog(null, "Cual es la posicin
del Registro que desea Eliminar. " + Print, "Eliminar datos vel vector",
JOptionPane.QUESTION_MESSAGE);
elemen1 =Integer.parseInt (Valor)-1;
if (elemen1 <= texto.length - 1) {
for (i =elemen1; i <= (texto.length - 1); i++) {
if (i != texto.length - 1) {
texto_t[i] = texto[i + 1];}}
texto= new String[texto_t.length - 1];
Print = "Numero de Registros " + texto.length + "\n\n";
for (i = 0; i <= (texto.length - 1); i++) {
texto[i] = texto_t[i];
Print = Print + "Posicin " + (i + 1) + ": " + texto[i] +
"\n";
}
}while(dato!=6);
}//fin metodo
}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&
int m;
int aux;
m = Integer.parseInt(JOptionPane.showInputDialog( "la
dimension del vector es:"));
int vecto[] = new int[m];
int n, l = 0;
vecto[i] =
Integer.parseInt(JOptionPane.showInputDialog("ingrese los datos:"));
}
n=
Integer.parseInt(JOptionPane.showInputDialog( "el numero a eliminar es:"));
int k;
l = i;
}
}
aux = vecto[i];
vecto[i] = vecto[i + 1];
vecto[i + 1] = aux;
}
int vector2[] = new int[m - 1];
for (int i = 0; i < vecto.length - 1; i++) {
vector2[i] = vecto[i];
}
System.out.println("LOS NUEVOS NUMEROS
SON");
for (int i = 0; i < vector2.length; i++) {
System.out.println("EL NUMERO "+vector2[i]+" ESTA
EN LA POSICION "+(i+1));
}
&&&&&&&&&&&&&&&&&&&
MATRIZTRANSPUESTA&&&&&&&&&&&&&&&&&&&&&&&
int [ ][ ]A ={{5,6,2,1,3},
{1,2,3,4,5},
{6,7,8,9,0}};
System.out.println( "La matriz dada es: " );
for(int i = 0; i < A.length; i++){
for(int j = 0; j < A[0].length; j++){
System.out.print( "" + A[i][j] + "");
}
System.out.println();
}