杭电ACM1.2.1 Biker's Trip Odometer
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=1§ionid=2&problemid=21 //author:pz 2 3 import java.text.DecimalFormat; 4 import java.util.Scanner; 5 6 public class Main{ 7 final double PI = 3.1415927; 8 final int InchesPerFoot = 12; 9 final int FeetPerMile = 5280; 10 final int SecondsPerMinute = 60; 11 final int MinutesPerHour = 60; 12 13 double diameter; 14 int revolutions; 15 double time; 16 double distance; 17 double mph; 18 19 static int count = 1; 20 21 Main(double diameter, int revolutions, double time){ 22 this.diameter = diameter; 23 this.revolutions = revolutions; 24 this.time = time; 25 } 26 27 void calculate(){ 28 DecimalFormat df = new DecimalFormat("0.00");//这里如果写 #.00 将会通不过。。。郁闷了很长时间 29 double perimeter = PI * diameter; 30 double inchesDistance = perimeter * revolutions; 31 double feetDistance = inchesDistance / InchesPerFoot; 32 distance = feetDistance / FeetPerMile; 33 double minuteTime = time / SecondsPerMinute; 34 double hourTime = minuteTime / MinutesPerHour; 35 mph = distance / hourTime; 36 System.out.println("Trip #" + count + ": " + df.format(distance) + " " + df.format(mph)); 37 count ++; 38 } 39 40 public static void main(String args[]){ 41 Scanner scan = new Scanner(System.in); 42 while(scan.hasNext()){ 43 double diameter = scan.nextDouble(); 44 int revolutions = scan.nextInt(); 45 if(revolutions == 0) 46 break; 47 double time = scan.nextDouble(); 48 Main trip = new Main(diameter, revolutions, time); 49 trip.calculate(); 50 } 51 } 52 }