Junior — Middle
Milliste meetoditega saab programmi main funktsioonile parameetreid edastada?
sobes.tech AI
Vastus AI-lt
In Java, the main function is usually declared as public static void main(String[] args). Parameters are passed via an array of strings args, which contains the command line arguments.
Example of passing parameters:
public class Main {
public static void main(String[] args) {
for (String arg : args) {
System.out.println(arg);
}
}
}
Running the program with parameters:
javac Main param1 param2
Options for passing parameters to main are limited to an array of strings. There are no other standard ways to pass parameters to main, but within the program, other data transfer methods can be used (e.g., via files, environment variables, system properties).