Printing array shows wrong output

前端 未结 3 801
感动是毒
感动是毒 2021-01-27 22:36

What is wrong with this code I\'m getting wrong output. I don\'t know what\'s wrong, I hope you could help me:

public class Main{
  public static void main(Strin         


        
3条回答
  •  离开以前
    2021-01-27 22:59

    The output is completely fine. The arrays don't override toString() method, so it invokes the Object#toString() method, which generates that kind of representation. The output is of the form:

    getClass().getName() + '@' + Integer.toHexString(hashCode())
    

    For arrays, the Class#getName() method uses some encoding for different element type to generate unique class name. The encoding rule is specified in the documentation.

    To get the human readable representation, you can use Arrays#toString() method:

    System.out.println("numbers are"+ Arrays.toString(data));
    

提交回复
热议问题