jueves, 16 de abril de 2015

Arreglos con switch
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package arreglos;

import javax.swing.JOptionPane;

/**
 *
 * @author FRANCO
 */
public class Arreglos {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int z;
        int[] A = new int[100];
        int i,s;
        int[] p = new int[100];
        int[] I = new int[100];
        int q,w;
        for(i=0;i<10;i++){
          A[i]=Integer.parseInt(JOptionPane.showInputDialog("ingrese valor al arreglo"));
        }
        do{
            z=Integer.parseInt(JOptionPane.showInputDialog("1.llenar Arreglo\n 2.muestra contenido\n 3.sumatoria elementos de Arreglo\n 4.busca valores pares y envia a un nuevo arreglo y busca impares y envia un nuevo arreglo\n 5. busca valores primos y envia al nuevo arreglo\n 6.invierte arreglo\n 7.ordena ascendentemente\n 8.ordena descendentemente\n 9.lista\n 10.salir\n  ¿Que opcion desea?"));
           switch(z){
               case 1:
                   for(i=0;i<10;i++){
            A[i]=Integer.parseInt(JOptionPane.showInputDialog("ingrese valor al arreglo"));
        }
         break;
               case 2:
             for(i=0;i<10;i++){
          JOptionPane.showMessageDialog(null,A[i]);
             }
          break;
         
          case 3:
          s=0;
           for(i=0;i<10;i++){
           s=s+A[i];
           }
            JOptionPane.showMessageDialog(null,"la suma es:"+s);
           break;
         
           case 4:
        q=0; w=0;
        for(i=0;i<10;i++){
          if(A[i]%2==0){
          p[q]=A[i];q++;
             }
          else
          {
          I[w]=A[i];w++;
             }
             }
          for(i=0;i<q;i++){
          JOptionPane.showMessageDialog(null,p[i]);
             }
          for(i=0;i<w;i++){
          JOptionPane.showMessageDialog(null,I[i]);
             }
          break;
          case 5:
             
         
          break;
         
          case 6:
         
          break;
         
         
          case 7:
          int j,auxiliar;
          for(i=0;i<10;i++){
                for(j=i;j<10;j++){
                    if(A[i]>=A[j]){
                        auxiliar=A[i];
                        A[i]=A[j];
                        A[j]=auxiliar;      
                    }}}
          break;
       
          case 8:
          for(i=0;i<10;i++){
                for(j=i;j<10;j++){
                    if(A[i]<=A[j]){
                        auxiliar=A[i];
                        A[i]=A[j];
                        A[j]=auxiliar;      
                    }}}
         
          break;
                   case 9:
              String mensaje1="";
              for(i=0;i<10;i++){
                  mensaje1=mensaje1+A[i]+"\n";}
                 JOptionPane.showMessageDialog(null,mensaje1);
              break;
         
           case 10:
          JOptionPane.showMessageDialog(null,"salir del programa");
    break;
       
           default:
          JOptionPane.showMessageDialog(null,"No es opcion valida");
             }
           }
           while(z!=10);
             
    }
}

jueves, 9 de abril de 2015

Programadores


 

Bienvenido al blog donde aprenderás y veras  una seria de programas creados en java NETBeans  para ayudarte en tu proceso como ingeniero o programador.

programdoresjavajf.