以实例请教高手,tostring的用法?
java吧
全部回复
仅看楼主
level 1
public class gugu{ static int a=10; static int b=18; static int c=23; public static void main(String args[]){ System.out.println("sum="+ (a+b+c)); } } 这是一个正确的、很简单的求和程序,请教高手:书上说把数字转换为string类型才能打印,那么这里为什么能够直接打印数字类型的a+b+c啊??请前辈们赐教!谢谢!
2006年06月02日 18点06分 1
level 1
补充一点,书上说要用public class gugu{ static int a=10; static int b=18; static int c=23; public String toString(){return "sum="+(a+b+c);}gugu a=new gugu();String h=a.toString();System.out.println(h);}}
2006年06月02日 18点06分 2
level 8
tostring();是StringBuffer类 转换为String类型的方法吧。
2013年07月23日 07点07分 4
level 8
(a+b+c)只是运算结果
2013年07月23日 07点07分 5
level 5
(a+b+c)只是运算结果 string+上其他东西就会生成新的字符串
2013年07月23日 07点07分 6
level 13
你这是自己写的tostring,java的jdk中有toString()方法。你可以看一下jdk的API,解释很清楚
2013年07月23日 07点07分 7
1