何らかの理由でaverageSpeedメソッドがdouble値または任意の値を返さない。何らかの理由でメソッドがメインメソッドに戻ることはないようです。なぜこのようなことが起こるのか分かりません。 私が入力した値は0,30,14,15,14,45になります。double 60.0が返されると思います。Java:メソッドがメインに戻らない
import java.util.Scanner;
/**
* Auto Generated Java Class.
*/
public class CarSpeed {
/**
* Computes a car's average speed over the legnth of a trip.
*
* @param milesStart odometer reading at the start of the trip
* @param milesEnd odometer reading at the end of the trip
* @param hrsStart hours on the (24 hour) clock at the start
* @param minsStart minutes on the clock at the start
* @param hrsEnd hours on the (24 hour) clock at the end
* @param minsEnd minutes on the clock at the end
* @return the average speed (in miles per hour)
*/
public static double averageSpeed(double milesStart, double milesEnd,
double hrsStart, double minsStart, double hrsEnd, double minsEnd) {
double distanceTraveled;
double minutes;
double hours;
double sixty;
double minuteHours; //minutes converted into hours
double time;
double averageSpeed;
distanceTraveled = milesEnd - milesStart;
minutes = minsEnd - minsStart;
sixty = 60;
minuteHours = minutes/sixty;
hours = hrsEnd - hrsStart;
time = minuteHours + hours;
averageSpeed = distanceTraveled/time;
return averageSpeed;
}
/**
* @param args
*/
public static void main(String[] args) {
double milesStart;
double milesEnd;
double hrsStart;
double minsStart;
double hrsEnd;
double minsEnd;
Scanner input = new Scanner(System.in);
System.out.print("What is the odometer reading at the start of the trip?");
milesStart = input.nextDouble();
System.out.print("What is the odometer reading at the end of the trip?");
milesEnd = input.nextDouble();
System.out.print("What is the hours on the 24 hr clock at the start?");
hrsStart = input.nextDouble();
System.out.print("What is the minutes on the clock at the start?");
minsStart = input.nextDouble();
System.out.print("What is the hours on the 24 hr clock at the end?");
hrsEnd = input.nextDouble();
System.out.print("What is the minutes on the clock at the end?");
minsEnd = input.nextDouble();
averageSpeed(milesStart, milesEnd, hrsStart, minsStart, hrsEnd, minsEnd);
}
}
使用デバッガ、それが呼び出された場合 – Jens
あなたはそれを呼び出すが、決してそれが返す値を格納するか、 – SomeJavaGuy
はい、私はこのQUを投稿するには余りにも性急だったかもしれないあなたに感謝印刷見るためにestion。私はあまりプログラミング経験を持っていないことに注意してください。だから私は、メソッドが返す値が印刷または保存されなければならないことを認識していませんでした。私は何らかの理由でそれが私のためになると思っていました。 – AceVariable