Muffin Muffin - 4 months ago 10x
Java Question

Java - user input/ arrays

So i'm having a hard time, finding ways on how to put integers inside the array, my objective is, make a program that a user will store 10 numbers and then after that display it.

So this is what I've done so far:

import java.util.Scanner;

public class wtf {
public static void main(String args[]){
Scanner input = new Scanner(;
int array[] = new int[10];

for(int i=1;i<array.length;i++){
System.out.print("Enter a number: ");
array[] = input.nextInt();

But unfortunately there is an error.


First of all you need to specify an index for the integer array object... every element of the array has its specific index... starting from 0 to n-1 where n is the number of elements in the array.. second of all, the index in programming always starts from 0 Index is often confused with position.. Position has its usual meaning starting from 1... consider an array having elements as 56 98 65 12

here 98 is at index 1 and at position 2

all u need to do now is

change the input line to: