0
Follow
0
View

Someone please answer the following question

diaowangqiang 注册会员
2023-02-28 04:25
  • in 1.3 Why do I need public static void main(String[] Public static void main(string [] args) this method? The section may solve your problem. You can read it carefully or in the source blog:
  • The main method is the entry method for Java programs, and the JVM looks for the main method first when it runs the program.

    The return value of the

    main method must be void, qualified by the static and public keywords.

czmike 注册会员
2023-02-28 04:25

It doesn't make any difference, either is fine; It's just an array definition. How you write it depends on your personal habits;

cs9_11 注册会员
2023-02-28 04:25

In Java, either method declaration is acceptable. This is because in Java, an array can access an element by adding a subscript to the array name, or it can access an element by adding a subscript to a pointer. The same is true for arrays of strings in Java, which can be declared as either String args[] or String[] args.

However, the second declaration, String[] args, is recommended because it is more consistent with the Java code style.

douniwan710 注册会员
2023-02-28 04:25

the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > in Java, using public static void main method as the entry point of the program. In the argument list for this method, we need to specify a String array of arguments to receive the command line input.

Java allows two ways to declare this parameter: String[] args and String args[]. The two declarations are syntactically equivalent, and both represent an array of strings named args.

Therefore, either public static void main(String[] args) or public static void main(String args[]) is the correct way to write it, and the choice is entirely up to personal preference and programming specifications. In general, it is more common to write with String[] args.

d20130101 注册会员
2023-02-28 04:25

both true, String args[] This is the same as in C, javaer is still more used to String[] args

poppo13422 注册会员
2023-02-28 04:25

This answer quotes ChatGPT

In Java, both public static void main(String args[]) and public static void main(String[] args) are available. This is because they are actually equivalent in that both declare a static method named main that takes an array of strings as its argument.

In the first form, the parameter is of type String[] and the parameter is named args. In the second, the argument is of type String and named args[]. In Java, the type and name of a parameter can swap places, so the two are equivalent.

Actually, String args[] is the C/C++ way to write it, and String[] args is the recommended way to write it in Java. Therefore, it is recommended to use String[] args to make the code more consistent with Java conventions and specifications.