vendredi 18 novembre 2016

Declaring array length, JAVA

I have to make two new arrays from this existing one, one will have positive values, and one negative, not including 0. If this logic is right, I only have one problem, declaring the length of these two, new arrays. I'm a beginer in programing.

public static void main(String[] args) {

int[] array = {12, 23, -22, 0, 43, 545, -4, -55, 43, 12, 0, -999, -87};
int[] array1 = new int [];
int[] array2 = new int [];

for(int i=0; i<array.length; i++)
{
if(array[i]>0)
{
    if(array[i]==0)
        continue;
    int[] array1 = new int[];

    array1[i]=array[i];
}
else if(array[i]<0)
{
    if(array[i]==0)
        continue;

    array2[i]=array[i];
}
}

Aucun commentaire:

Enregistrer un commentaire