+ 1

Why we need to declare arrays before printing or returning from a method

https://code.sololearn.com/cofg0jgMUc3m/?ref=app

21st Aug 2020, 6:02 AM
Bhavuk Sharma
Bhavuk Sharma - avatar
3 odpowiedzi
+ 2
Because Java always has to know the type of the variable even when you print it as it has to use the toString method for printing it
21st Aug 2020, 6:43 AM
Eliya Ben Baruch
Eliya Ben Baruch - avatar
+ 1
@WkutaBenBaruch in the above code when we print the array without keywords new int[] it is not working and trowing an error (Syntax error, insert "VariableDeclarators" to complete LocalVariableDeclaration) why is this ?
21st Aug 2020, 6:28 AM
Bhavuk Sharma
Bhavuk Sharma - avatar
0
What do you mean by declaring? Giving a data type?
21st Aug 2020, 6:22 AM
Eliya Ben Baruch
Eliya Ben Baruch - avatar