So for my cs class, I had to write a program. Long story short, I submit it to an autograder which provides feedback. The autograder provides hints if we do not pass all the tests. One of the hints was that my code apparently seemed to go into an infinite loop for some test cases, but I do not know where this could possibly happen in my code. Can someone point me in the right direction to where I may be going wrong? I'll provide my code below:
public class TwoLargest {
public static void main(String[] args){
double largest = Double.NEGATIVE_INFINITY;
double secondLargest = Double.NEGATIVE_INFINITY;
int numNums = 0;
System.out.print("Please enter a terminating value: ");
double termValue = IO.readDouble();
System.out.println("Please enter your list of numbers: ");
while(true){
double temp = IO.readDouble();
numNums++;
if((temp == termValue && numNums < 2) || temp == termValue && numNums == 2){
IO.reportBadInput();
numNums = 0;
System.out.println("Please try again: ");
continue;
}
if(temp == termValue){
break;
}
if (temp > largest) {
secondLargest = largest;
largest = temp;
}
else if (temp > secondLargest) {
secondLargest = temp;
}
}
IO.outputDoubleAnswer(largest);
IO.outputDoubleAnswer(secondLargest);
}
}