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