/*
*测试float型数值、
*/
public class FloatTest
{
public static void main(string[] args)
{
float x=22.2f;
float y=42.6f;
float z=x*y;
System.out.println(x + "*" + y + "=" + z);
}
}
我的问题就是帮忙详细的解释一下这个括号里为什么要这样写
(x + "*" + y + "=" + z)
*测试float型数值、
*/
public class FloatTest
{
public static void main(string[] args)
{
float x=22.2f;
float y=42.6f;
float z=x*y;
System.out.println(x + "*" + y + "=" + z);
}
}
我的问题就是帮忙详细的解释一下这个括号里为什么要这样写
(x + "*" + y + "=" + z)
第二,你是初学,我也是初学,大家理解!“”表示原样输出
比如System.out.println(6+"");
输出字符67
System.out.println(6+7);
输出字符13
比如System.out.println(6+"7");
输出字符67
System.out.println(6+7);
输出字符13
括号里面是这样的
x + "*" + y + "=" + z
x 、 y 、z是变量,放在这里将输出它们的值
"*" 、 "=" 是常量 ,如果要在屏幕上输出常量,则要用引号引起来
它们之间用 + 号连起来,在这里,+起到连接的作用。
但是:System.out.println(6+7);
这个加号会把6和7相加
所以你要清楚+在什么时候起什么用
所以最终结果是这个样子的:
22.2*42.6=435.372
float x=22.2f;
System.out.println("x"); 结果是:x
System.out.println(x); 结果是:22.2
屏幕上就直接显示X
X
屏幕上就显示22.2f你的输出结果就是22.2f * 42.6f =