What is the function of string args[in this program? I've learned c++,string args[] like what's in C + +? If it is C + +, want to output string as long as write cout<< "..." <<endl; on it, void Main () The parentheses are empty, and Java Why write String args[]? Class example{public static void Main (String args[]) { System.out.println ("This is a simple Java program."); }}
Since string args[] or string[] args represents an array of strings to the main method, then System.out.println (args[]); Why is it an error, args[] is not the string that is a simple Java Program? String args[] What is the relationship with this is a simple Java program? If that's okay, why is there an error removing string args[in the program?What is the difference between the main function without string args[] and the main function with string args[]? Tell me more about it,
String[] args This string array is the argument that is entered when the main function is saved, for example, the class name of the main function is test so you run Java test a b c in cmd, args[0] = A, AR Gs[1]=b, args[2]=c You can invoke the variables you have entered in your program. Args[] Isn't that the string this is a simple Java program? It's totally not, you don't understand. Well, when you run it, add a parameter, such as Java Test XX. Then add this phrase to your main function: System.out.println ("Arg is" +args[0]) and see what the output is? is not this: it is a simple Java Programarg is xx You can also try this, enter Java Test xx yy zz at run time, and add this paragraph in your main function: System.out.println ("Arg is "+args[0]+" "+args[1]+" "+args[2]" and see what the output is? Is not: This is a simple Java programarg is xx yy zz Now do you understand? If that's okay, why is there an error removing string args[in the program? --------The reason why the error is that the main function without string args[] and the main function with string args[] are essentially not the same function, and Java itself does not have a main function without string args[]. So of course it went wrong.
What is the role of string args[in Java programs?