command prompt - Why cant we give array of values to a String in main function in Java? -


class helloworld{     public static void main(string args[4]){         system.out.println("hello world!");     } } 

is wrong give string args[4] ? why cant mention value inside string args[4] ?but should output hell,but there wrong.the code not executing properly.

you getting args parameter. array created when program runs. content of args array not known @ compile time (not size), therefore not make sense make assertions @ compile time size. reason array never contains length in type signature.

if need check size, correct way writing condition, such as:

if (args.length != 4) {     //do error handling stuff } 

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -