title: can no methods be declared in the main method?
body: <p>I wrote this class (to print the array list) and in it I made a method in the <code>main</code> function..</p>
  
  <p>Well it didn't work: I made the function <code>static</code> and declared it in the <code>main</code> method, still it didn't work. In the main method I made the function without an access specifier: still it didn't work.</p>
  
  <p>Can't you declare a method in the <code>main</code> method?</p>
  
  <p>Isn't there any way to declare a method inside the main method (other than making it public static outside the main method)?</p>
  
  <pre><code>public class TestArrays {
  
  
      public static void main(String[] args) {
      // Step 1 &amp; 2: declare/initialize array variables
      int[]  array1 = { 2, 3, 5, 7, 11, 13, 17, 19 };
      int[]  array2;
  
      // Step 3: display array1 with initial values
          System.out.print("array1 is ");
      printArray(array1);
      System.out.println();
  
      // Step 4: make array2 refer to array1
      array2 = array1;
      // modify array2
      array2[0] = 0;
      array2[2] = 2;
      array2[4] = 4;
      array2[6] = 6;
      // print array 1
      System.out.print("array1 is ");
      printArray(array1);
      System.out.println();
  
  
       static void printArray(int[] array) {
      System.out.print('&lt;');
      for (int i:array ) {
        // print an element
        System.out.print(i);
        // print a comma delimiter if not the last element
  
        }
         System.out.print('&gt;');
      }
    }
  </code></pre>