How do I make an integer vector without knowing its Java length

1

I need to store the prime divisors of an 'x' number in an array Since I do not know how many prime divisors that number has, I can not determine the size of the array.

import java.util.Scanner; 
public class vectorDivisoresPrimos { 
    public static void main(String[] args) { 
        // TODO Auto-generated method stub 
        int n,m=0; 
        Scanner scan= new Scanner(System.in); 
        n = scan.nextInt(); 
        for(int i=1;i<n;i++) 
        { 
            m=EsPrimo(i); 
            if(n%i==0&&m<2) 
            { 
                //Aquí es donde necesito guardar a 'i' en el array o la lista// 
            } 
        } 
    } 
    public static int EsPrimo(int x) 
    { 
        int c=0; 
        for(int j=1;j<x;j++) 
        { 
            if(x%j==0)  c++; 
        } 
        return c; 
    } 
}
    
asked by José 09.06.2018 в 16:14
source

0 answers