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