System.out.printIn()如何接受整数? [英] How can System.out.printIn() accept integers?

查看:372
本文介绍了System.out.printIn()如何接受整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我几天前开始学习java并得到一个问题。对于下一个表达式:

So I started learning java several days ago and got a question. For the next expression:

String foo=123;

是不允许的。但是,在 System.out.printIn()中,我们可以使用以下内容:

is not allowed. However, in System.out.printIn(), we can use something like:

int x=5;
System.out.println(x);

由于不允许隐式地为字符串分配整数,为什么上面的表达式有效?任何人都可以给出详细解释吗?我也想知道我们什么时候可以使用这种隐含的东西,何时我们不能。

Since implicitly assigning a integer to a string is not allowed, why the expression above works? Anyone can give a detailed explanation? I'm also wondering when can we use this kind of implicit thing and when we cannot.

推荐答案

有太多的重载方法 PrintStream System.out

println(boolean x)
println(char x)
println(int x)
println(long x)
println(float x)
println(double x)
println(char x[])
println(String x)
println(Object x)

这篇关于System.out.printIn()如何接受整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆