java中int跟float的运算结果是float类型还是double类型?

wubufu1234567 2014-09-16 01:23:56
.........................
...全文
11546 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ix_fly 2014-09-16
  • 打赏
  • 举报
回复
引用 8 楼 u011172283 的回复:
这类问题我感觉自己写个小程序验证一下就好了吧
非常赞同,最重要的的是我们的目标值是什么类型
沉思的猿某人 2014-09-16
  • 打赏
  • 举报
回复
这类问题我感觉自己写个小程序验证一下就好了吧
rumlee 2014-09-16
  • 打赏
  • 举报
回复
引用 6 楼 u010475149 的回复:
[quote=引用 2 楼 rumlee 的回复:] 是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
抛开楼主问题本身。 这个代码可能不能作为凭据,因为重载是在编译器就确定的,而不是运行期。[/quote] 是的,你说的是对的,重载是在编译器确定的。但是 10*10f 结果是什么类型,也是在编译器确定的啊。这有什么问题吗? 基本类型数据的类型有在运行期确定的吗?只有引用指向的类型才有可能在运行期才能确定啊。
as1dasd11 2014-09-16
  • 打赏
  • 举报
回复
引用 2 楼 rumlee 的回复:
是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
抛开楼主问题本身。 这个代码可能不能作为凭据,因为重载是在编译器就确定的,而不是运行期。
须莫有 2014-09-16
  • 打赏
  • 举报
回复
java 中的自动转换 从位数低的类型向位数高的类型转换。是FLOAT类型的!你自己可以写个列子试试!
S117 2014-09-16
  • 打赏
  • 举报
回复
float 类型
skyWalker_ONLY 2014-09-16
  • 打赏
  • 举报
回复
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;
	}
rumlee 2014-09-16
  • 打赏
  • 举报
回复
是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
xiuyute 2014-09-16
  • 打赏
  • 举报
回复
int 的结果是整数, float 是带小数的,结果是float类型的
as1dasd11 2014-09-16
  • 打赏
  • 举报
回复
引用 7 楼 rumlee 的回复:
[quote=引用 6 楼 u010475149 的回复:] [quote=引用 2 楼 rumlee 的回复:] 是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
抛开楼主问题本身。 这个代码可能不能作为凭据,因为重载是在编译器就确定的,而不是运行期。[/quote] 是的,你说的是对的,重载是在编译器确定的。但是 10*10f 结果是什么类型,也是在编译器确定的啊。这有什么问题吗? 基本类型数据的类型有在运行期确定的吗?只有引用指向的类型才有可能在运行期才能确定啊。[/quote]、 学习了、。

62,614

社区成员

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

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