import java.io.*;
public class A
{
  public static void main(String[] args)
  {
    StringBuffer str= new StringBuffer("Happy Holidays");
    toUpper(str);
  }
  public static void toUpper(StringBuffer s1)
  {
    int i,j; char str1[]= new char[25];
    for(i=0,j=0; i<s1.length(); i++,j++)
    {
      if(Character.isLowerCase(s1.charAt(i)))
        str1[j]=(char)(s1.charAt(i)-32);
      else
        str1[j]= s1.charAt(i);
    }
    System.out.println("the result is: "+str1);
  }
}为何现在程序输出结果为:the result is: [c@f5da06 而不是HAPPY HOLIDAYS
而将System.out.println("the result is: "+str1);改成System.out.println(str1),便能输出HAPPY HOLIDAYS

解决方案 »

  1.   

    System.out.println("the result is: "+str1);
    System.out.println(str1)前者调用的是
    println(String)方法
    相当于String s = "the result is: "+str1;
    System.out.println(s);后者调用的是
    println(char[])方法
      

  2.   

    楼上的能分析下调用println(String)方法后的输出结果为何是the result is: [c@f5da06 ?
      

  3.   

    类型的问题
    这样就能输出HAPPY HOLIDAYS
    String r=new String(str1);
    System.out.println("the result is: "+r);
      

  4.   

    现在我想弄懂的问题是调用println(String)方法后的输出结果为何是the result is: [c@f5da06 ? 谢谢
      

  5.   

    俺来讲给你听System.out.println()支持好多参数,最终还是把这些参数转化为String,但转化方法不同,是根据这些参数的类结构来转的
    char []str1;
    System.out.println(str1);会通过输出流将char[]一个一个输出,简单点讲就是把str1的每一个char输出,自然结果是对的System.out.println("sfsfd"+str1);
    这种形式等于
    String s="sfsafsdf"+str1.toString();
    char[]也是一个Object,也支持toString方法,这里就是通过这个方法得到String
    然后再把这个String打印出来,结果就是你看到的那个了,实际上是str1这个对象的toString结果,而不是char[]的内容理解否