title: Java, why is Math.sqrt() returning 0
body: <p>I'm trying to check if a number is a square, and if a number is triangular.
  The issue is happening at <strong>sqrt(num)</strong> which is returning 0 for all numbers I test.<br>
  I'm using an online compiler, tried several compilers, so it's not a compiling issue. Tried to declare num as a double and as an int, same results.<br>
  I'm new to Java, but not new to programming, I searched online, checked my code several times, everything looks fine, it even worked as expected before adding the variables for checking triangular number, but after declaring the variables checkTri and checkTriSqr, this started to happen. I'm sure this have nothing to do with declaring these variables (almost sure), could anyone please help me understand what's going on here? </p>
  
  <pre><code>import static java.lang.Math.sqrt;
  import static java.lang.Math.round;
  
  public class Parent{
  
  public static void main(String[] args){
  
      class Number
      {
          public int num ;
          double numSqr = sqrt(num );
          double roundNumSqr =  round(numSqr) ;
          double checkTri = 8 * num + 1 ;
          double checkTriSqr = sqrt(checkTri) ;
  
          public void prinTest()
          {
              System.out.println(num);
              System.out.println(numSqr);
              System.out.println(roundNumSqr);
              System.out.println(checkTri);
              System.out.println(checkTriSqr);
          }
  
          public boolean isSqr()
          {
              if (numSqr == roundNumSqr)
              {
                  return true;
              }
              else
              {
                  return false;
              }
          }
  
          public boolean isTriangular(){
  
              if (checkTriSqr * checkTriSqr == checkTri )
              {
                  return true;
              }
              else
              {
                  return false;
              }
          }
      }
  
      Number number = new Number();
  
      number.num = 350;
      number.prinTest();
      System.out.println(number.isSqr());
      System.out.println(number.isTriangular());
   }
  }
  </code></pre>
  
  <p>EDIT: The following screen shot is from the tutorial I'm following, concerning declaring classes within methods!</p>
  
  <p><a href="https://i.stack.imgur.com/AGW0l.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AGW0l.jpg" alt="enter image description here"></a></p>