Java Array返回奇怪的输出 [英] Java Array returning weird output

查看:60
本文介绍了Java Array返回奇怪的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为作业问题创建一种方法,该方法可返回数组中的最大值。我正在使用for

循环将数字输入到数组中。输入代码如下所示。

I'm creating a method for a homework problem that returns the highest value in an array. I'm using a for
loop to input the numbers into the array. Here is what the input code looks like.

int[] array = new int [n];
    for(i=0;i<array.length;i++){
        array[i]=sc.nextInt();
        System.out.println(array);}

当我运行程序尝试并查看是否存在任何错误,因为我注意到数组未返回我输入到其中的值。例如,
将数字 12 放回 [I @ 6c80d028 。我对Java很陌生,所以我真的不知道输入是怎么回事。

When i run the program to try and see if there's anything wrong as a I go along I notice the array not returning the value I input into it. For example putting the number 12 it returns [I@6c80d028. I'm pretty new to java so I don't really know what's going on with the input. Is there any thing that can be done?

推荐答案

请使用:

System.out.println(Arrays.toString(array));

这篇关于Java Array返回奇怪的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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