title: Cows in the FooLand city
body: <p>I was going through this problem-</p>
  
  <blockquote>
    <p>Cows in the FooLand city are interesting animals. One of their
    specialties is related to producing offsprings. A cow in FooLand
    produces its first calve (female calf) at the age of two years and
    proceeds to produce other calves (one female calf a year).</p>
    
    <p>Now the farmer Harold wants to know how many animals would he have at
    the end of N years, if we assume that none of the calves die, given
    that initially, he has only one female calf?</p>
    
    <p>Input:</p>
    
    <p>The first line contains a single integer T denoting the number of test
    cases. Each line of the test case contains a single integer N as
    described in the problem.  </p>
    
    <p>Output:</p>
    
    <p>For each test case print in new line the number of animals expected at
    the end of N years</p>
  </blockquote>
  
  <p>I solved this by below code-</p>
  
  <pre><code>public static void main (String[] args)
  {
      Scanner ab=new Scanner(System.in);
      int t=ab.nextInt();  //number of test cases
  
      for (int i=0;i&lt;t;i++)
      {
          int n=ab.nextInt(); //years
          int arr[]=new int[n];
          arr[0]=1;
          arr[1]=2;
          if(n&gt;2)
          {
              for(i=2;i&lt;n;i++)
              {
                  arr[i]=arr[i-1]+arr[i-2];
              }
          }
          System.out.println(arr[arr.length-1]);
  
  
       }
  }
  </code></pre>
  
  <p>But when i searched on net they have given a much complex solution at net-</p>
  
  <p><a href="https://hackerranksolutionc.blogspot.in/2017/10/cows-of-fooland.html" rel="nofollow noreferrer">https://hackerranksolutionc.blogspot.in/2017/10/cows-of-fooland.html</a></p>
  
  <p>I tried matching the output and found the result is same for small numbers but is different for very large number.</p>
  
  <p>I want to know that is there anything wrong in my solution?</p>