title: I keep on getting an Exception in thread "main" java.lang.NumberFormatException: For input string: "exit"
body: <p>My code looks like this. It compiles fine and runs fine until I enter "exit" in the JOptionPane window. "exit" is meant for the code to stop and display the average, min, max, and range. When I enter exit it prints</p>
  
  <pre><code>Exception in thread "main" java.lang.NumberFormatException: For input string: "exit"
  at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
  at sun.misc.FloatingDecimal.parseFloat(FloatingDecimal.java:122)
  at java.lang.Float.parseFloat(Float.java:451)
  at Loop2.main(Loop2.java:41)
  
  
  
  import javax.swing.JOptionPane;
  public class Loop2
  {
      public static void main(String [] args)
      {
          float max = 0;//Integer.MIN_VALUE;
          float min = 0;//Integer.MAX_VALUE;
          float sum = 0;
          float num = 0;
          int count = 0;
          float average = 0;
          float range = 0;
          String userInput;
  
          userInput = JOptionPane.showInputDialog( "Enter a value. " , null);
          num = Float.parseFloat(userInput);
  
          if (!userInput.equals("exit"))
          {
          num = Float.parseFloat(userInput);
          min = num;
          max = num;
  
          }//end if
  
          while (!userInput.equals("exit") )
          {
              sum = sum + num;
              count++;
  
          if( num &gt; max )
          {
             max = num;
          } 
  
          if( num &lt; min )
          {
             min = num;
          }
  
          userInput = JOptionPane.showInputDialog( "Enter a value. " , null);
          num = Float.parseFloat(userInput);
  
          } //end while
  
          average = (sum) / (count);
  
          System.out.println( "Average: " + average );
  
          range = (max) - (min);
  
          System.out.println( "Range: " + range );
  
          System.out.println( "Minimum value: " + min );
  
          System.out.println( "Max value: " + max );  
     }
  }
  </code></pre>