What's Difference Between These Statements is this same? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What's Difference Between These Statements is this same?

public static void main(String[ ] args) public static void main(String [ ]args) public static void main(String args [ ])

11th Jan 2020, 6:28 PM
Mr. Nothing
Mr. Nothing - avatar
4 Answers
+ 13
1D Array Declaration ------------------------------- int a[] ; int[] a; int []a; =>All are valid 2D Array Declaration -------------------------------- int[][] a; int[][] a; int a[][]; int[] []a; int[] a[]; int []a[]; =>All are valid 3D Array Declaration -------------------------------- int [][][]a; int[][][] a; int a[][][]; int[] [][]a; int[] a[][]; int[] []a[]; int[][] []a; int[][] a[]; int []a[][]; int [][]a[]; =>all are valid But Make sure that here some example to find dimension of the variable 1)int[] a,b; => { a=1D , b=1D } 2) int[] a[] , b; => { a= 2D , b= 1D (note it ) } 3) int [] []a , b; = { here a= 2D , b = also. 2 D} =>Be careful about 2nd and 3 rd example now last and very dangerous example 4)int [] a , b[]; 5)int[][] a, []b; these two are generate compile time error conclusion =>if we want to specify the the dimension before or after the variable .this rule is applicable only for 1st variable.
12th Jan 2020, 8:13 AM
Saroj Patel
Saroj Patel - avatar
+ 4
All the same
11th Jan 2020, 6:33 PM
Anthony Tannous
Anthony Tannous - avatar
+ 2
also can: public static void main(String [] args) <-- JVM read it as same
11th Jan 2020, 6:47 PM
cxvowevski
cxvowevski - avatar
0
Thanks for clearing Doubt 😊
12th Jan 2020, 4:53 AM
Mr. Nothing
Mr. Nothing - avatar