是float类型 可以用以下程序测试一下public class Test { public void test(float f) { System.out.println("float"); } public void test(double d) { System.out.println("double"); } public void test(int i) { System.out.println("int"); } public static void main(String[] args) { Test t = new Test(); int i = 10; float f = 10f; t.test(f * i); } } 输出结果为float
float类型,java自动类型转换会将int类型向上转换为float类型,可以看下面的代码,如果是double类型的话则需要强制类型转换:public static void main(String[] args) { int i = 5; float f =3.5f; double b; float f1; f1 = i * f;//若int和float的运算结果为double,则需要像下面那样强制类型转换 b = i * f; f1 = (float) b; }
可以用以下程序测试一下public class Test {
public void test(float f) {
System.out.println("float");
} public void test(double d) {
System.out.println("double");
} public void test(int i) {
System.out.println("int");
} public static void main(String[] args) {
Test t = new Test();
int i = 10;
float f = 10f;
t.test(f * i);
}
}
输出结果为float
int i = 5;
float f =3.5f;
double b;
float f1;
f1 = i * f;//若int和float的运算结果为double,则需要像下面那样强制类型转换
b = i * f;
f1 = (float) b;
}