我知道得到一个int的倒数会是这样的:
int foo = 5;
float recip = 1/foo;
Run Code Online (Sandbox Code Playgroud)
但你怎么去获得一个浮点数的倒数呢?会不会这样?现在我让用户输入倒数,这不是最佳的.有任何想法吗?
编辑
为了澄清这里的一些伪代码:
float input = 0.25;
int recip = (get reciprocal here);
System.out.println(recip); //should return 4
Run Code Online (Sandbox Code Playgroud)
谢谢!