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