title: How can I find the largest value n in this Collatz Conjecture code I created?
body: <p>I am a beginner coder, and I am trying to find the largest value of n, but I am having trouble. I have tried to use a for loop to search each element of the array I created, but the code returns 0 every time. Is this method correct? I have tried entering the values of n into an array, but I am not sure if this is the correct method to go about solving this goal.</p>
  
  <pre><code>import java.util.*;
  public class CollatzConjecture {
      private static int max;
      public CollatzConjecture(int maximum){
          int max=maximum;
      }
      public static void main(String[] args) {
  
          ArrayList&lt;Integer&gt; arr = new ArrayList&lt;Integer&gt;();
          Scanner scan = new Scanner(System.in);
          System.out.print("Type an integer: ");
          int n = scan.nextInt();
          int count = 0;
  
          while(n&gt;1)
          {
              if(n%2 == 0)
                  {n = n/2;}
              else
                  {n = 3*n + 1;}
              System.out.println(n + " ");
              count++;
  
              arr.add(n);
              arr.get(n);
          }   
  
          for(int i = 0; i&lt;arr.size()-1; i++)
          {
              if(arr.get(i) &gt; max)
              {
                  int max = arr.get(i);
              }
          }
  
  
          System.out.println(arr);
          System.out.println("Terminated after " + count + " steps");
  
          }
  }
  </code></pre>