Why main method in java has to be (String. []args)?

I am confused on why main method on java has to be:

public static void main(String[] args)

My code is

public class MergeSorted 
{
    public static void main (int[] nums1, int m, int[] nums2, int n) 
    {
       ----
    }
}

Will executing >>java MergeSorted [2,4,5,0,0,0],3,[1,3],2; help?

Note: This question is edited by far.[the comments are not relevant as of now], I apologize for the inconvience

Answer

You have to have it as you will run the program as a command line application. It it is javax application would be requiring a main method.

MergeSort.java

public class MergeSort {
   public static void main(String[] args) {
      // get input via input stream
      mergeSort(...); // call method
   }

   public static void mergeSort(int[] nums1, int m, int[] nums2, int n) {
      // logic here
   }
}

Leave a Reply

Your email address will not be published. Required fields are marked *