Very new to Java (please don't laugh)and trying to do a project that asks user for a number and will keep track of the highest and lowest number when the user enter a sentinel value. My error is the I cannot get max and min values to update when going through the while loop.
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a double number, or 'q' to quit");
double currentNum = 0.0;
double maxNum=0.0;
double minNum=0.0;
int count = 0;
while(sc.hasNextDouble())
{
currentNum = sc.nextDouble();
count++;
System.out.println(count);
if(count ==1)
{
minNum = currentNum;
maxNum = currentNum;
System.out.println("Please enter a double number, or 'q' to quit");
}
else if(count!=1){
if (currentNum > maxNum)
{
currentNum = maxNum;
System.out.println("You are in currentNum > maxNum");
System.out.println(maxNum);
System.out.println("Please enter a double number, or 'q' to quit");
System.out.println(maxNum);
}
else if (currentNum < minNum)
{
currentNum = minNum;
System.out.println("You are in currentNum < minum");
System.out.println("Please enter a double number, or 'q' to quit");
}
}
}
System.out.println("Min num " + minNum);
System.out.println("Max num " + maxNum);
}
}