When defining the main function
public void main(String[] args)
You do it like this. Here
What is String [args] and what is this for?
In Java, args is an array of String objects in the command line. When you run Java on the command line, you can use the parameters It's used to support the delivery. For example, in the command line,
If you run java MyProgram one two
, the args will contain ["one"",two"].
If you want to check it out, turn the repeat statement and look at the output.
public class MyProgram {
public static void main(String[] args) {
for(int i = 0; i < args.length; i++) {
System.out.println(args[i]);
}
}
}
© 2024 OneMinuteCode. All rights reserved.