title: print average numbers
body: <p>I am new to java.And so i am practising some questions.But i got stumbled over this.I know i am very close to the right answer and i am thinking of putting a else condition that if it less than 0.it will break.
  Tried inserting this here and there but it cannot work.</p>
  
  <p>Write a method named printAverage that accepts a Scanner for the console as a parameter and repeatedly prompts the user for numbers. Once any number less than zero is typed, the average of all non-negative numbers typed is displayed. Display the average as a double, and do not round it. For example, a call to your method might look like this:</p>
  
  <pre><code>Scanner console = new Scanner(System.in);
  printAverage(console);
  The following is one example log of execution for your method:
  
  Type a number: 7
  Type a number: 4
  Type a number: 16
  Type a number: -4
  Average was 9.0
  If the first number typed is negative, do not print an average.
  </code></pre>
  
  <p>My attempt:</p>
  
  <pre><code>  public static void printAverage(Scanner console){
  
      int num=0;
      double sum=0;
      double avg=0;
      int counter=0;
      while(num&gt;=0){
     System.out.print("Type a number: ");
       num=console.nextInt();
  
          if(num&gt;0){
       sum+=num;
       counter++;
      avg=sum/counter;
          }
  
  
      }
      System.out.println("Average was " +  avg);
  
  
  }
  </code></pre>
  
  <p>Sorry.The question was not clear.For example,when i type in 0 0 1 1 -2 as the numbers.I am supposed to get </p>
  
  <p>Type a number: 0
  Type a number: 0
  Type a number: 1
  Type a number: 1
  Type a number: -2
  Average was 0.5</p>
  
  <p>But i am getting</p>
  
  <p>Type a number: 0
  Type a number: 0
  Type a number: 1
  Type a number: 1
  Type a number: -2
  Average was 1.0</p>