+1

Why in main method in java we use array of strings as parameters not any integer or other

I tried but it doesn't work

7/15/2019 2:53:51 PM

Nishant Singh

7 Answers

New Answer

+2

Java only recognizes the main method if it has an array of strings of arguments.

+1

Wait you pretty much asked the same question twice.

+1

Nishant Singh Array - because you can pass more than one value String - Because they are universal way to represent data. If it was int, how would you pass strings or float. If it was float then due to the fact that all float values cannot be represented accurately there could be inaccurate data passed, precision loss due to conversion issues etc. Doesn't work ? Not possible whatever you pass will be passed as string. You will need to convert it to appropriate type before use.

+1

What kind of arguments would string[] args get?

+1

Nishant Singh If you are not passing anything to main, then array length is zero. void is for return type not for the arguments try to pass data from command line like java <correct class path> myprog 1 2 3 check for args.length in main, if > 0 run a for loop to print the data. in the for loop try to assign the data directly to int like int val = args[i]; and see if that works

0

What is this airee u answered all my questions in the same way

0

Swim u must int instead of string and make coding just for no. And show does it work and next thing is if u use void then why it matters to use string as argument I am not passing anything to main method