'I am creating a program that will give a report on race times and I am trying to place them in first, second, third but when I compile I get zeros?
public void sortTimesAscending() {
//Finding which racer is first place
if (timeOne > timeTwo && timeOne > timeThree) {
timeOne = firstPlace;
}else if (timeTwo > timeOne && timeTwo > timeThree) {
timeTwo = firstPlace;
}else if (timeThree > timeOne && timeThree > timeTwo) {
timeThree = firstPlace;
}
//Finding which racer is third place
if (timeOne < timeTwo && timeOne < timeThree) {
timeOne = thirdPlace;
}else if (timeTwo < timeOne && timeTwo < timeThree) {
timeTwo = thirdPlace;
}else if (timeThree < timeOne && timeThree < timeTwo) {
timeThree = thirdPlace;
}
//Finding which racer is second place
if (timeOne != firstPlace && timeOne != thirdPlace) {
timeOne = secondPlace;
}else if (timeTwo != firstPlace && timeTwo != thirdPlace) {
timeTwo = secondPlace;
}else if (timeThree != firstPlace && timeThree != thirdPlace) {
timeThree = secondPlace;
}
System.out.println("First Place (time in seconds): " + firstPlace);
System.out.println("Second Place (time in seconds): " + secondPlace);
System.out.println("Third Place (time in seconds):" + thirdPlace);
}
The output I get is : First Place (time in seconds): 0.0 Second Place (time in seconds): 0.0 Third Place (time in seconds):0.0
How can I fix this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
