怎么样得到它的数据类型

猪头小哥 2013-10-31 06:43:26
public class Test {

public static void main(String[] args)
{
System.out.print(12 + 3);//输出的结果的数据类型怎么得到?
}
}
...全文
192 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
猪头小哥 2013-11-01
  • 打赏
  • 举报
回复
引用 8 楼 huxiweng 的回复:
12+3是int。只不过print方法用String.valueOf把int转成了string 看API: print public void print(int i) Prints an integer. The string produced by String.valueOf(int) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method. Parameters: i - The int to be printed See Also: Integer.toString(int)
OK
teemai 2013-11-01
  • 打赏
  • 举报
回复
12+3是int。只不过print方法用String.valueOf把int转成了string 看API: print public void print(int i) Prints an integer. The string produced by String.valueOf(int) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method. Parameters: i - The int to be printed See Also: Integer.toString(int)
猪头小哥 2013-11-01
  • 打赏
  • 举报
回复
引用 6 楼 ghostkngiht 的回复:
是要这东西???

System.out.println(new Integer(12+3).getClass());
不是,那个结果应该是String类型,你这样得到的是Integer类型。
ghostkngiht 2013-11-01
  • 打赏
  • 举报
回复
是要这东西???

System.out.println(new Integer(12+3).getClass());
maoyinglm 2013-10-31
  • 打赏
  • 举报
回复
是String类型的吧,参考 public void print(int i) 打印整数。按照平台的默认字节编码将 String.valueOf(int) 生成的字符串转换为字节,并完全以 write(int) 方法的方式写入这些字节。 调用Integer类中的toString()方法转换成String字符串
825609451 2013-10-31
  • 打赏
  • 举报
回复
引用 3 楼 jinpengqi 的回复:
SOUT 的输入出类型都是String!
print()有很多重载
  • 打赏
  • 举报
回复
SOUT 的输入出类型都是String!
zhuweisyyc 2013-10-31
  • 打赏
  • 举报
回复
判断类型只能 instance of 大多数的框架判断未知类型都是这样做的。
时光清浅 2013-10-31
  • 打赏
  • 举报
回复
这是int~

62,612

社区成员

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

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