#include #define P 3.1415927#define toFeet(x) x/12.0#define toMiles(x) x/5280.0int main(){ double diameter;//直徑 int revolutions;//轉數 double time;//香蕉 double s; int count=1; while(scanf("%lf%d%lf",&diameter,&revolutions,&time),revolutions){ time/=3600; diameter/=63360; s=diameter*P*revolutions; printf("Trip #%d: %.2lf %.2lf\n",count++,s,s/time); }}
稍有改動
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
final double PI = 3.1415927;
Scanner scan = new Scanner(System.in);//標准輸入流
int a = scan.nextInt();//首先輸入有多少組數據
double x[][] = new double[a][3];//用二維數組存放數據 直徑 轉數 時間 依次輸入就可以 空格 回車都可以分隔
for (int i = 0; i < x.length; i++) {
for (int j = 0; j < x[i].length; j++) {
x[i][j]=scan.nextLong();
}
}
scan.close();//關閉標准輸入流
int count = 1;
for (int i = 0; i < x.length; i++) {
x[i][2] /= 3600;
x[i][0] /= 63360;
double s = x[i][0]*PI*x[i][1];
System.out.println(String.format("Trip #%d: %.21f %.21f", count++,s,s/x[i][2]));
}
}
public static double toFeet(double x){//進行換算的方法 傳入x返回換算的值 調用方法toFeet(x);
return x/12.0;
}
public static double toMiles(double x){
return x/5280.0;
}
}
運行結果截圖: