title: How can i display an error message in Java
body: <p>I am a beginner, and I have to write a code that calculates the area and circumference from the radius the user gives me. that part was easy, but the teacher also wanted me to only accept valid integers and have the user re-enter a value when his input is incorrect ...</p>
  
  <p>so i was able to have it display the error message for every case except when they enter an negative integer:</p>
  
  <pre><code> import java.util.Scanner;
   public class GetCircle
   {
       public static void main(String []args)
       {
  
      Scanner input = new Scanner(System.in);
       int radius;
       do {
      System.out.print("Please enter size of radius (Must be integer): ");
      while (!input.hasNextInt()) {
          System.out.print("That is not a valid number, please try again :");
          input.next();
      }
  
      radius = input.nextInt();
  
      } while (radius &lt; 0);
  
      System.out.println("The radius is: " + radius);
  
      }
  }
  </code></pre>
  
  <p>and so this is what I get as a result:</p>
  
  <blockquote>
    <p>Please enter size of radius (Must be integer): aaa</p>
    
    <p>That is not a valid number, please try again :4.5555</p>
    
    <p>That is not a valid number, please try again :-5</p>
    
    <p>Please enter size of radius (Must be integer): -5</p>
    
    <p>Please enter size of radius (Must be integer): -8.777</p>
    
    <p>That is not a valid number, please try again :-4</p>
    
    <p>Please enter size of radius (Must be integer):</p>
  </blockquote>
  
  <p>** so whenever its a negative integer it doesn't display the error message...</p>
  
  <p>how can i fix this please?</p>