I wrote the following function:
public void enterlessonnames(String[] names)
{
String msg="";
for (int i=0;i<names.length;i++)
{
msg=msg+names[i];
}
System.out.println(msg);
}
I want to call like that, giving the input:
enterlessonnames({"math","art"} );
How can i call this in main?
enterlessonnames(names[{"math","art"} ]);
It does not any of them.
Multiple markers at this line:
- Syntax error, insert ")" to complete MethodInvocation
- Syntax error on token ",", delete this token
- Syntax error, insert ";" to complete Statement
- Syntax error on tokens, delete these tokens
like this:
enterlessonnames( new String[] { "a", "b" } );
FYI, java naming conventions imply that method names have first letter of each word in the name start with a capital letter except for the first word that starts with non-capital. In your case: enterLessonNames
.
You need to create a proper String array instance, something like this:
String[] array = new String[]{"math", "art"};
Your fixed call would be:
enterlessonnames( new String[]{"math", "art"} );
or
String[] lessons = new String[]{"math", "art"};
enterlessonnames(lessons);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With