阵列印刷怪异的性格 [英] Array printing weird character

查看:134
本文介绍了阵列印刷怪异的性格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个程序,它从一个数组中删除一个给定的字符,然后打印出新的数组,每当我打印出来我得到这样奇怪的结果[I @ 120acab

 公共静态INT [] removeVal(INT [] numArray,INT VAL)
{
    INT吹扫= 0;
    INT保留= 1;
    INT arrayVal = 0;
    对于(INT项目:numArray)
    {
        如果(项目== VAL)
        清洗吹扫= + 1;
        其他
        继续保持= + 1;
    }
    INT [] newArray =新INT [保持]
    对于(INT塔科:numArray)
    {
        如果(塔科!= VAL)
            newArray [arrayVal] =塔科;
            arrayVal = arrayVal + 1;
    }
    返回newArray;
}


解决方案

您应该使用的 Arrays.toString 打印的数组。这将显示该阵列的各个元素

默认的toString 实施对象类返回你所看到的。

I'm trying to create a program that removes a given character from an array and then prints out the new array and whenever I print it out I get weird results like [I@120acab

public static int[] removeVal(int[] numArray, int val)
{
    int purge = 0;
    int keep = 1;
    int arrayVal = 0;
    for (int item : numArray)
    {
        if(item == val)
        purge = purge + 1;
        else
        keep = keep + 1;
    }    
    int[] newArray = new int[keep];
    for (int taco : numArray)
    {
        if(taco != val)
            newArray[arrayVal] = taco;
            arrayVal = arrayVal + 1;
    }
    return newArray;
}

解决方案

You should use Arrays.toString to print the array. This will show the individual elements of the array.

The default toString implementation of Object class returns what you see.

这篇关于阵列印刷怪异的性格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆