Código:
/* * 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 numparvecsolopar; import java.util.*; /** * * @author Joan */ public class NumParVecSoloPar { /** * @param args the command line arguments */ public static void main(String[] args) { int [] v1; v1 = new int[6]; introVector(v1); buscaPar(v1); } public static void introVector(int [] v){ Scanner teclado=new Scanner (System.in); for(int i=0;i<v.length;i++){ System.out.println("Introduce un valor para la posición "+i); v[i]=teclado.nextInt(); } } public static void buscaPar(int [] v){ int rest, cont=0; for(int i=0;i<v.length;i++){ int div=(int)v[i]; rest=div%2; if(rest==0){ cont+=1; } } //nuevo vector para los pares int [] vPar; vPar = new int[cont]; for(int i=0;i<v.length;i++){ int div=(int)v[i]; rest=div%2; if(rest==0){ for(int j=0;j<vPar.length;j++){ vPar[j]=(int)v[i]; } } } for(int i=0;i<v.length;i++){ System.out.print(v[i]); } System.out.println(""); for(int i=0;i<vPar.length;i++){ System.out.print(vPar[i]); } } }