Will not let me convert from int to int []

0

Greetings, I had to make a double-dimension array but it does not let me store integer values in that array, however in a dimension yes, why does this happen?

public static void main(String[] args) 
{
    Scanner sc = new Scanner(System.in);

    int primerDim, segDim;
    int cont = 0;

    System.out.println("Introduce la primera dimensión: ");
    primerDim = sc.nextInt();

    System.out.println("Introduce la segunda dimensión: ");
    segDim = sc.nextInt();
    sc.close();

    int[][] doble = new int[primerDim][segDim];

    for (int i = 0; i < doble.length; i++) 
    {
        cont++;
        doble[i] = cont;
        for (int j = 0; j < doble.length; j++) 
        {
            cont++;
            doble[j] = cont;
        }
    }

}
    
asked by AlejandroB 30.01.2018 в 18:46
source

1 answer

1

In the loop , you have to assign using the two dimensions.

Something like this:

for (int i = 0; i < doble.length; i++) 
{
    for (int j = 0; j < doble[i].length; j++) 
    {
        cont++;
        doble[i][j] = cont;
    }
}
    
answered by 30.01.2018 / 18:50
source