어떤 이유로 Java에서 averageSpeed 메소드가 double 값 또는 임의의 값을 반환하지 않습니다. 메소드가 어떤 이유로 main 메소드로 결코 빠져 나오지 않는 것 같습니다. 나는 이것이 왜 일어나는 지 이해하지 못한다. 입력 한 값은 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