我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!
天气: 晴朗
心情: 高兴
/*fileName:P5Q08.java
*Name:Wang Chaoran
* Description:
8 (Conversions between feet and meters)
Write a class that contains the following two methods:
// Converts from feet to meters //
public static double footToMeter(double foot)
// Converts from meters to feet //
public static double meterToFoot(double meter)
The formula for the conversion is:
meter = 0.305 * foot
Write a test program that invokes these methods to display the following tables:
Feet Meters Meters Feet
1.0 0.305 20.0 65.574
2.0 0.61 25.0 81.967
...
9.0 2.745 60.0 195.721
10.0 3.05 65.0 213.115
*/
public class P5Q08{
public static void main(String[] args){
System.out.println("Feet Meters Meters Feet");
for(double i = 1.0; i<=10.0; i++){
if(i<10.0)
System.out.print(" ");
System.out.print(i+" ");
System.out.printf("%5.3f",footToMeter(i));
System.out.print(" "+(i*5+15)+" ");
System.out.printf("%7.3f",meterToFoot(i*5+15));
System.out.println();
}
}
public static double footToMeter(double foot){
return 0.305 * foot;
}
public static double meterToFoot(double meter){
return meter/0.305;
}
}
导入论坛查看(36)回复(0)引用(0)好评(0) 差评(0)
加入收藏
编辑
审核
TAG:
computing