viernes, 8 de junio de 2018

EJERCICIO 4


1.       Diseñar un programa que capture N números por teclado  con el JOPTIONE y muestre el vector únicamente con los números impares.



CÓDIGO FUENTE

package manu;
import javax.swing.JOptionPane;
/**
 *
 * @author Admin
 */
public class Discretas {   
    public static void main(String[] args) {      
            String v = JOptionPane.showInputDialog("INGRESE LOS COMPONENTES DEL VECTOR DE LA FORMA\n 1,2,3,4,5,6,7,8,9,,,N");
            String[] vec=v.split(",");
            int[] vec2 = new int[vec.length];
            for (int i=0; i<vec.length; i++) {
                vec2[i] = Integer.parseInt(vec[i]);
            }
            for (int i=0; i<vec.length; i++) {
                if (vec2[i]%2!=0) {
                    System.out.print (vec2[i]);
                }  else{
                    System.out.print(",");
                }
            }     }

    } 

SALIDA





No hay comentarios.:

Publicar un comentario

VENTANAS DE DIALOGO

Que Es? JOptionPane es una Clase que nos provee una serie de ventanas de dialogo predefinidas con el fin de facilitarnos algunos proces...