程序如下:
import java.io.*;
public class fd { 
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
int I = 0;
char[] ch = new char[5];
while (I++ < 1) {  
InputStreamReader stdin = new InputStreamReader(System.in);
System.out.print("Enter a line:");

System.out.println(stdin.read( ch ) );
System.out.println("the array is " + ch );
System.out.println("the array is " + ch[0] );

for( int i=0; i<ch.length; i++ )
System.out.println( ch[i] );

char[] c ="gfdsgs".toCharArray();
System.out.println( c );
}
}
运行结果如下:
Enter a line:fd
4
the array is [C@a90653
the array is f
f
d
有的字符这里显示不了, 最好各位能亲自运行下, 
想问的问题是:
[C@a90653是什么东西?
两次数组打印为何效果不一样 ?谢谢!

解决方案 »

  1.   

    ch.toString()方法的自动调用
    ch的hashcode
      

  2.   

    jungle1171(jungle) 能详细一点么? 我好像看明白了点 但 ~~~
    [C@a90653似乎是hashcode的结果

    System.out.println("the array is " + ch );
    System.out.println( c );
    调用方式相同阿
      

  3.   

    Object.toString()This is a handy method. You can call it explicitly, and it will return a string that "textually represents" this object. It's actually the name of the class of the object, the "@" sign, and the address of the object. Use it while debugging to see if your objects really are what you thought they were. These lines in file ClockView.java will invoke Object's toString() on a Timestamp object, and print the String.
      

  4.   

    哎呀 是 toString(),
    那为何两次调用方式相同 结果不一样呢?
      

  5.   

    System.out.println("the array is " + ch );
    System.out.println( c );
    are different:
    System.out.println("the array is " + ch ); is calling System.out.println(String str)
    System.out.println( c ); is calling System.out.println( char[] charArray);And "the array is " + ch will automaticlly call "the array is " + ch.toString().
      

  6.   

    To Lz
    System.out.println("the array is " + ch );
    System.out.println( c );
    的调用结果之所以不同在于  "the array is " +  这个东东;
    用了+连接,ch就要在打印前转化为String类型,实际上是用的println(String)重载;
    而第二句的c依然是Char[],使用println(char[])重载,你可以把System.out.println( c );改写成System.out.println( "asdfds" + c );,会看到和第一个句是一样的结果;我也是小菜鸟,不知道是不是解释的清楚~~~
      

  7.   

    Oo...
    kinzz() 所言极是
    大家发帖很快~~~
      

  8.   

    jungle1171(jungle) ( ) 信誉:100    Blog  2007-02-08 17:23:38  得分: 0  
     
     
       To Lz
    System.out.println("the array is " + ch );
    System.out.println( c );
    的调用结果之所以不同在于  "the array is " +  这个东东;
    用了+连接,ch就要在打印前转化为String类型,实际上是用的println(String)重载;
    而第二句的c依然是Char[],使用println(char[])重载,你可以把System.out.println( c );改写成System.out.println( "asdfds" + c );,会看到和第一个句是一样的结果;我也是小菜鸟,不知道是不是解释的清楚~~~  
     
    他说到了问题所在,我已经试过了,的确是因为"the array is " + 的问题,要是去掉就可以了,不会再出现the array is [C@a90653这种问题
      

  9.   

    [C@a90653 表示的是一个对象的地址。
    例如类C有两个属性String str和int i,c是类C的一个对象,现在你要用System.out.println把c打印出来,但是c有两个属性,系统怎么样才把两个属性都打印出来呢?--呵呵,系统没有办法^_^ 只好打印出一个地址来了。