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' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -