java - Why does my code print [I@87816d when i run this code? -


this question has answer here:

/*  * given array of positive ints, return new array of length "count" containing  * first numbers   * original array. original array contain @ least "count" numbers.  */  public class stringex  {      public static void main(string[] args)      {         int[] nums = {2,3,5,6,8};         int count = 2;         stringex s1 = new stringex();         system.out.println(s1.copyevens(nums, count));      }     public int[] copyevens(int[] nums, int count)      {        int[] n=new int[count];        int c=0;          for(int i=0;i<nums.length;i++)         {             if(nums[i]%2==0&&c!=count)             {                 n[c]=nums[i];                 c++;              }         }          return n;     } }  // output:[i@87816d 

arrays don't have nice tostring method. use object.tostring, gives

getclass().getname() + '@' + integer.tohexstring(hashcode()) 

which unhelpful. use arrays.tostring if want readable representation.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -