java中二维数组相关问题希望大神指教

joe_Sduty 2017-09-18 06:53:36
int[][] scores ={{1,2,3},{4,5,6},{7,8,9}};//定义一个二维数组并赋予初值
for(int i = 0 ;i<scores.length; i++){
for(int j=0 ;j<scores[i].length; j++){
System.out.print(Arrays.toString(scores[i][j]));//这行代码有问题,说是The method toString(long[]) in the type Arrays is not applicable for the arguments (int)
}System.out.println();
}
}


我想输出的时候运用Arrays中toString功能中间加一个逗号分隔符,但是出现了问题怎么办
...全文
405 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
joe_Sduty 2017-09-20
  • 打赏
  • 举报
回复
非常感谢,以后多多指教
偏安zzcoder 2017-09-19
  • 打赏
  • 举报
回复
The method toString(long[]) in the type Arrays is not applicable for the arguments (int) 这句话的意思是这个方法需要的参数是long型的数组,而你调用这个方法的实参却是一个int型的变量,所以报错。 两种简单的改法:

1、
import java.util.Arrays;

public class Test {
	public static void main(String[] args) {
		int[][] scores ={{1,2,3},{4,5,6},{7,8,9}};//定义一个二维数组并赋予初值
		for(int i = 0 ;i<scores.length; i++){
			System.out.print(Arrays.toString(scores[i]));
		}
	}
}
输出结果:
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]

2、
import java.util.Arrays;

public class Test {
	public static void main(String[] args) {
		int[][] scores ={{1,2,3},{4,5,6},{7,8,9}};//定义一个二维数组并赋予初值
		for(int i = 0 ;i<scores.length; i++){
			for(int j=0 ;j<scores[i].length; j++){
				System.out.print(scores[i][j]+",");
			}
			System.out.println();
                }
	}
}
结果:
1,2,3,
4,5,6,
7,8,9,

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧