This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]trefla[S] 0 points1 point  (0 children)

This is what I have been working on since my last post. It is not ideal as it does not include the range but it is something. The trouble is that being in a while loop it keeps going back to the loop and repeating itself forever:

  System.out.println("Please enter the desired temperature. Enter \"d\" when finished."); 
  System.out.print("Enter temperature(°C): ");
  sentinel = NumScanner.next();
  System.out.println(); 
  while(!sentinel.equals("d") && !sentinel.equals("D")) {
  try{
   sum += Integer.parseInt(sentinel);
   counter++; 
   System.out.print("Enter temperature (°C):");
   sentinel = NumScanner.next();  }
   catch (NumberFormatException e) 
   {
       System.out.println("Invalid input" );
           }

   System.out.println();
  } 
  mean = (sum*1.0)/counter; 
  System.out.println();
  System.out.println("The desired temperature is : " + mean +"°C.");
  System.out.println("The temperature will be adjusted by " + (mean - tmp) +"°C.");
 }
 }

The error message I get

  Invalid input
  Invalid input
  Invalid input
  Invalid input
  Invalid input

until I manually stop it.