title: Array not initialized properly
body: <p>I went searching on this forum for someone having a problem similar to mine and I was not able to find why on earth my program is not working properly besides looking solid. I'm just starting to learn Java so I'm not sure if there is some kind of syntax error going on here or if it's more but I have been staring at it, and this website for the past hour and I'm not seeing what's wrong.</p>
  
  <pre><code>public class BubbleSort {
  
      public static void main(String[] args) {
          int a, b, n, change, i, operations, choice;
          Scanner input = new Scanner(System.in);
          System.out.println("Would you like to add your own numbers?");
          System.out.println("enter '1' for no and '2' for yes");
          choice = input.nextInt();
  
          if (choice == 1) {
              int[] array = {
                  5,
                  7,
                  3,
                  9,
                  1,
                  0,
                  6
              };
              n = 7;
          } else if (choice == 2) {
  
              System.out.println("How many numbers would you like to add to the" +
                  "Array? (Add up to 10)");
              n = input.nextInt();
  
              int array[] = new int[n];
  
              System.out.println("Input " + n + " integers");
  
              for (a = 0; a &lt; n; a++) {
                  array[a] = input.nextInt();
              }
          }
  
          System.out.println("Bubble Sort operation:");
  
          for (a = 0; a &lt; (n - 1); a++) {
              System.out.print("iteration " + (a + 1) + ": ");
  
              for (b = 0; b &lt; n - a - 1; b++) {
                  if (array[b] &gt; array[b + 1]) {
  
                      change = array[b];
                      array[b] = array[b + 1];
                      array[b + 1] = change;
                      operations++;
  
                  }
              }
              for (i = 0; i &lt; n; i++) {
                  System.out.print(array[i]);
              }
              System.out.println();
          }
  
          System.out.print("Finished array after bubble sort: ");
          for (i = 0; i &lt; n; i++) {
              System.out.print(array[i]);
          }
          System.out.println();
          System.out.println("This operation took " + operations + " cycles");
          System.out.println();
      }
  }
  </code></pre>
  
  <p>It's just a simple bubble sort program but I'm seriously stumped here. Any ideas what would be wrong? The error says that <code>n</code> is never initialized.</p>