Saturday, 31 August 2013

This code is printing array 0 0 0 0 0 5 and not the actual array

This code is printing array 0 0 0 0 0 5 and not the actual array

class ArrayPrint {
static void arrayPrinter(int[] x) {
for(int i=0;i<x.length;i++) {
System.out.println(x[i]);
}
}
public static void main(String...S) {
int[] x = {3,3,4,2,7};
x = new int[5];
arrayPrinter(x);
System.out.println(x.length);
}
}
Actual array is not printing, it is printing 0 0 0 0 0. Please help
correct the error

No comments:

Post a Comment