ayuda para programacion

29
boolean ban = false, opmenu = true; Scanner leer = new Scanner(System.in); int pos = 0, elem = 0, tam, elembuq, xpos = 0, temp, numactualizar, op; int num[] = null; String imp = " "; do { op = Integer.parseInt(JOptionPane.showInputDialog(null, "MENU DE OPCIONES\n" + "1.llenar\n2. Imprimir\n 3.Buscar \n 4.Ordenar\n 5.actualizar\n 6.Salir")); switch (op) { //tamaño del arreglo case 1: do { try { tam = Integer.parseInt(JOptionPane.showInputDialog("ingrese el tamaño del arreglo: ")); num = new int[tam]; ban = true; } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null, "ingrese el dato correcto please:"); ban = false; }

Upload: lawiet-elle

Post on 08-Sep-2015

225 views

Category:

Documents


1 download

DESCRIPTION

código de programacion

TRANSCRIPT

boolean ban = false, opmenu = true; Scanner leer = new Scanner(System.in); int pos = 0, elem = 0, tam, elembuq, xpos = 0, temp, numactualizar, op; int num[] = null; String imp = " "; do { op = Integer.parseInt(JOptionPane.showInputDialog(null, "MENU DE OPCIONES\n" + "1.llenar\n2. Imprimir\n 3.Buscar \n 4.Ordenar\n 5.actualizar\n 6.Salir")); switch (op) { //tamao del arreglo case 1: do { try { tam = Integer.parseInt(JOptionPane.showInputDialog("ingrese el tamao del arreglo: ")); num = new int[tam]; ban = true; } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null, "ingrese el dato correcto please:"); ban = false; } } while (ban == false); //do{

// 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")); for (pos = 0; pos < num.length; pos++) { if (num[pos] == elembuq) { ban = true; xpos = pos; break; } } if (ban == true) { JOptionPane.showMessageDialog(null, "Se encontro el numero en la posicion: " + xpos); } else { JOptionPane.showMessageDialog(null, "No se encontro el numero"); } break; case 4: //ordenar imp=""; for (pos = 0; pos < num.length; pos++) { for (xpos = 0; xpos < num.length - 1; xpos++) {

if (num[xpos] > num[xpos + 1]) { temp = num[xpos]; num[xpos] = num[xpos + 1]; num[xpos + 1] = temp; } } } //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);

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() { int num[]=new int [0]; int num_tem[]=new int[0]; String opcion; int dato; int elemento1 = 0, elemento2 = 0; do{ opcion=JOptionPane.showInputDialog ("Menu Vectores de tipo Entero\n 1. Ingresar \n2. Modificar\n 3. Eliminar\n 4. Mostrar\n 5. Salir"); dato=Integer.parseInt (opcion); switch(dato) { case 1: if(num.length==0) {num=new int[1]; num[0]=Integer.parseInt (JOptionPane.showInputDialog ("Ingrese el valor " ));} else if(num.length>0) {num_tem=new int [num.length+1]; for(int i=0;i