码迷,mamicode.com
首页 > 其他好文 > 详细

Miles per gallon to kilometers per liter

时间:2015-06-24 10:33:01      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

Miles per gallon to kilometers per liter

1 Imperial Gallon = 4.54609188 litres 
1 Mile = 1.609344 kilometres
1英制加仑=4.54609188升
1英里=1.609344千米
mpg=每加仑行驶的英里数(miles per gallon)

 

Description:

Sometimes, I want to quickly be able to convert miles per gallon into kilometers per liter.

Create an application that will display the number of kilometers per liter (output) based on the number of miles per gallon (input).

Make sure to round off the result to two decimal points.

Some useful associations relevant to this kata: 1 Imperial Gallon = 4.54609188 litres 1 Mile = 1.609344 kilometres

using System;
public static class Kata
{
  public static double Converter(int mpg)
  {
    // do your magic
    double kpl = mpg * 1.609344 / 4.54609188;
    return Math.Round(kpl,2);
  }
}

 

Miles per gallon to kilometers per liter

标签:

原文地址:http://www.cnblogs.com/chucklu/p/4596805.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!