这段程序输出乱码是怎么回事

may1232 2011-08-15 10:09:19
public class ArrayTest {

public static void main(String[] args) throws NumberFormatException, IOException {
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
System.out.println("please input a number");
int n;
n = Integer.parseInt(br.readLine());
System.out.println(n);


int[][] arrayOut=new int[n][n];
arrayOut[0][0]=1;
int row=0;
int column=0;
for(;row<n;row++){
for(;column<n;column++){
arrayOut[row][column]++;
}

}

System.out.print(arrayOut);






输出:
please input a number
2
2
[[I@de6ced
...全文
77 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
luohuijun619 2011-08-15
  • 打赏
  • 举报
回复
这那是乱码,你直接输出任何一个数组都是这样的,数组你不能直接输出,得用循环遍历,
sup_davi 2011-08-15
  • 打赏
  • 举报
回复
直接打印数组中的每个元素,再用两层for循环就可以

import java.io.*;


public class Csdn2 {

public static void main(String[] args) throws NumberFormatException, IOException {
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
System.out.println("please input a number");
int n;
n = Integer.parseInt(br.readLine());
System.out.println(n);


int[][] arrayOut=new int[n][n];
arrayOut[0][0]=1;

for(int row=0;row<n;row++){
for(int column=0;column<n;column++){
arrayOut[row][column]++;
}
}

//System.out.print(arrayOut);

for(int row=0;row<n;row++){
for(int column=0;column<n;column++){
System.out.print(arrayOut[row][column] + " ");
}
System.out.println();
}

}
}
飞跃颠峰 2011-08-15
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 may1232 的回复:]

引用 1 楼 zl3450341 的回复:

[[I@de6ced

这个不是乱码, 数组是一个对象,你这样打印的是他的内地址。。

这样不能打印出他中的每一个元素的


那要怎么样才能直接输出元素啊?谢谢
[/Quote]

for (int i=0;i<arrayOut.length;i++) System.out.println(Arrays.toString(arrayOut[i]));
wenbodong 2011-08-15
  • 打赏
  • 举报
回复
用java.util.Arrays
Arrays.toString(outArray);
may1232 2011-08-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zl3450341 的回复:]

[[I@de6ced

这个不是乱码, 数组是一个对象,你这样打印的是他的内地址。。

这样不能打印出他中的每一个元素的
[/Quote]

那要怎么样才能直接输出元素啊?谢谢
may1232 2011-08-15
  • 打赏
  • 举报
回复
[Quote=引用楼主 may1232 的回复:]
public class ArrayTest {

public static void main(String[] args) throws NumberFormatException, IOException {
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedRe……
[/Quote]

那要怎么样才能直接输出元素啊?谢谢
zl3450341 2011-08-15
  • 打赏
  • 举报
回复
[[I@de6ced

这个不是乱码, 数组是一个对象,你这样打印的是他的内地址。。

这样不能打印出他中的每一个元素的

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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