0
In java ,main method consists of (String[]args) why it can't accept integer arguments?
2 Answers
+ 4
Tathvik
Whenever you take user input then it is considered as string input so if you take input 2 then it is actually a string not integer. To convert input to integer we use Integer.parseInt().
So here args is a string array which can contains any type of value but that would be string. So args accepts every type of arguments even integer also but you need to parse like
int a = Integer.parseInt(args[0]);
+ 3
main method is a special method .
its pre defined by java like that.
cli (command line interface) arguments and other environment variables are passed by jvm to your program through that args string array .
you can try printing it to know more about it...
https://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html