统计信息

  • 访问数:12291
  • 博客数:142
  • 建立时间:2008-01-05
  • 更新时间:2008-05-21
我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!

P5Q08

2008-04-08 16:42:38

天气: 晴朗 心情: 高兴

/*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;
  }

}
 


加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

Powered by X-Space 1.2 © 2001-2006 Comsenz Technology Ltd