+ 3
Why main take string as argument? đ
2 Answers
+ 12
in public static void main(String args[]) args is an array of console line argument whose data type is String. in this array, you can store various string arguments by invoking them at the command line
simply to see what it stores you can put this in your main method to see yourself
for(int i = 0; i < args.length; i++) {
System.out.println("Argument is: "+args[i]);
}
+ 7
String is non primitive datatype so it is easy to convert any other primitive datatypes like int, double,etc.Commonly we get string array and converts it into a required type.
If there is any other reasons behind this?