0

Should the argument of the main method in java always be a string?I am a noobie in java

main method in java

20th Nov 2017, 1:10 PM
Jose Dominic
Jose Dominic - avatar
2 ответов
+ 9
String args[], which is actually an array ofjava.lang.String type, and it's name is args here. It's not necessary to name it args always, you can name it strArrayor whatever you like In Java args contains the supplied command-line arguments as an array of String objects. In other words, if you run your program as java MyProgram one two then args will contain ["one", "two"]. If you wanted to output the contents of args, you can just loop through them like this... public class ArgumentExample { public static void main(String[] args) { for(int i = 0; i < args.length; i++) { System.out.println(args[i]); } } }
20th Nov 2017, 1:24 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 1
Args always needs to represent an array of strings because that is what the operating system will pass it.
20th Nov 2017, 1:38 PM
josh mizzi
josh mizzi - avatar