karma karma - 1 year ago 67
Java Question

What is the variable 'i' mean after the array declaration

I came across a Java program to merge sort some numbers. Here is a snippet of the code which I am a bit confused with.

int n;
Scanner in=new Scanner(System.in);
int A []=new int[n],i;

In the above code the line
int A []=new int[n],i;
What does this
stand for. Is it a declaration of an int variable called
? Or does it have another meaning. Your advice will be appreciated.

Answer Source

It is declaration of int type variable. But it is more better to declare that int i in for like this

for(int i = 0; i < n; ++i)

Also more whitespaces increase code readability

You can declare variables like this TYPE var1, var2, var3, ..., varN;

And all variables will have same type

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download