title: Java - Receiving a missing return error
body: <p>I started taking a Java class last week and one of my assignments is to create a program that will take the GCD of two numbers, using what we have learned in class so far (so my program is probably not the most efficient). This is my program.</p>
  
  <pre><code>import java.util.*;
  public class Program {
      public static void main(String[] args) {
          Scanner console = new Scanner(System.in);
          System.out.print("Enter an integer");
          int num1 = console.nextInt();
          System.out.print("Enter an integer");
          int num2 = console.nextInt();
          int gcd = factor(num1, num2);
          System.out.println("The GCD is " + gcd);
      }
  
      public static int factor(int num1, int num2) {
          int big = Math.max(num1, num2);
          int small = Math.min(num1, num2);
          int bigabs = Math.max(Math.abs(num1), Math.abs(num2));
          int smallabs = Math.min(Math.abs(num1), Math.abs(num2));
  
          if (smallabs == 0) {
              return bigabs;
          }
          if ((bigabs == 1) || (smallabs == 1)) {
              return 1;
          }
          for (int i = smallabs ; i &gt;= 1; i--) {
              if ((num1 % i == 0) &amp;&amp; (num2 % i == 0)) {
                  return i;
              } 
          }
          // This is where I need a return statement
      }
  }
  </code></pre>
  
  <p>It can't compile because it's missing a return statement. I believe that is because a method which requires a return type must declare a return statement for every possible branch in the method (correct me if I'm wrong). I know that in any scenario the numbers will go through the for loop's if statement, but the method doesn't know that. So my question is what return statement should I put? Does it really matter? Can someone explain this to me in detail because I have not learned much yet.</p>