我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!
天气: 晴朗
心情: 高兴
/*P3Q4
* Wang Chaoran
* Description:4 (Conversion from miles to kilometers)
Write a program that displays the following table (note that 1 mile is 1.609 kilometers):
Miles Kilometers
1 1.609
2 3.218
...
9 14.481
10 16.09
*/
import java.text.DecimalFormat;
public class P3Q4
{
public static void main(String[] args)
{
DecimalFormat df = new DecimalFormat("0.000");
double kilometers=0;
int Miles=0;
String space = " ";
//Print the initial line
System.out.println("Miles Kilometers");
//Print the other lines
for(Miles=1; Miles <11;Miles++)
{
if (Miles >9)
{
space = " ";
}
kilometers = Miles*1.609;
System.out.println(Miles+space+df.format(kilometers));
}
}
}
导入论坛查看(24)回复(0)引用(0)好评(0) 差评(0)
加入收藏
编辑
审核
TAG:
computing