我刚开始学习java,需要基础知识的帮助。我编写了将光速转换为每秒公里数的代码。代码如下所示:
public class LightSpeed
{
private double conversion;
/**
* Constructor for objects of class LightSpeed
*/
public LightSpeed()
{
conversion = (186000 * 1.6); //186000 is miles per second and 1.6 is kilometers per mile
}
/**
* Print the conversion
*/
public void conversion()
{
System.out.println("The speed of light is equal to " + conversion + " kilometers per second");
}
}
我需要在转换中包含逗号,这样数字就不会全部一起运行。而不是看起来像 297600.0 的数字,我需要它看起来像 297,600.0。有人请帮忙!谢谢