Can not return an array in java? -


this question has answer here:

the program below aims return nonzero values in array using array b.

i new java, experienced c++.

would gladly appreciate feedback !

public class first  {     static int [] a= { 5, 43, 0, 127, 1, 0 ,0 ,3};      public static int[] nonzeros( int [] )     {          int [] b= new int [10];         int k=0;         for(int i=0;i<=7;i++)             if(a[i]!=0)             {                  b[k]=a[i];                 k++;             }           return b;     }                         public static void main(string[] args)                         {                               system.out.println(nonzeros(a));                         } } 

output:

 [i@659e0bfd 

use:

system.out.println(arrays.tostring(nonzeros(a))); 

in main method.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -