有什么方法可以获得整数值并以双倍显示? [英] There is any way to get value in integer and display it in double?
本文介绍了有什么方法可以获得整数值并以双倍显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我的示例代码:
package javanew;
Here is my just example code:
package javanew;
public class JavaNew
{
public static void main(String args[])
{
int a,b;
double c;
a=11;
b=2;
c=a/b;
System.out.println(c);
}
}
Output:
5.0
现在,如果我将int更改为double,则输出为5.5。所以,如果我想从整数中获取用户的输入值并将结果显示为double,那么它的方法是什么?
Now if I change the int into double then output is 5.5. so if I want to get input value from user in integer and display result in double, what is the way for it?
推荐答案
你可以进行转换:
You can do casting :
c = (double)a / b;
我不知道java但你可以尝试这个,如果它工作与否。
祝你好运。
I don't know java but you can try this if it works or not.
Good luck.
这篇关于有什么方法可以获得整数值并以双倍显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文