title: How can I input an if statement inside a while loop?
body: <pre><code>import java.util.Scanner;
  public class ex11 
  {
  static Scanner type=new Scanner(System.in);
      public static void main(String args[])
      {
          int fact=1;
          System.out.println("Enter a natural number ");
          int num=type.nextInt();
  
          int i=1;
          while(i&lt;=num)
          {
              fact*=i;
              i++;    
          }
          System.out.println("Factorial of number " + num + " is " + fact);
      }
  }
  </code></pre>
  
  <p>I'm trying to place a conditional statement inside the while loop. The condition is to test for would be that of, if num is a negative number, <code>S.O.P.("You entered a negative #");</code> in other words,</p>
  
  <pre><code>if(num&lt;0)
      S.O.P.("You entered a negative #");
  </code></pre>
  
  <p>However it doesn't print it properly. </p>