The output keeps showing 0, how can I change it? I want to print the user's array however my output takes the users input and print 0
public static void main(String[] args) {
int i;
int userArray[] = new int [50];
Scanner lagoScan = new Scanner(System.in);
System.out.print("Input Column of Array: ");
int colInput = lagoScan.nextInt();
for(i=1; i<= colInput; i++) {
userArray [i] = lagoScan.nextInt();
}
System.out.println(userArray[i]);
}
colInputyou just have the number of columns. You are not accepting the data that you want to save. Accept the data, put it in array and then print output inside the for loopiis inSystem.out.println(userArray[i]);? Answer: It is greater than the last index that you have entered data for.