"Cannot convert int type to int[]" error when running Java program

Asked 3 months ago, Updated 3 months ago, 8 views

When I wrote the program below, I received an error saying that I could not convert the int type to int[].
I want to do this because I want to set the two-dimensional array from [0][0][9][9] and substitute elements from 1 to 100, but I can't because of an error.I looked for various places, but I didn't know, so I posted it.Could you give me some advice?
Thank you for your cooperation.

package kadai;

public class Kadai1 {

    public static void main(String[]args) {

        int[][]Array=new int[10][10];

        for (int Count=0; Count<10;Count++) {
            Array [Count] = Count +1;
            for (int Count 2 = 0; Count < 10; Count 2++)
                Array [Count2] = Count2+1;




2022-09-30 14:23

1 Answers

The variable Array is a two-dimensional array of int because it is declared and substituted as shown below.In other words, Array is an array of int arrays.

int[][] Array = new int[10][10];

However, some lines are substituted as follows:This is the cause of the error.

Array [Count] = Count+1;

On the left is an array of int, and on the right is an int.

If you want to substitute the int value, Array [somehow]You must specify two subscripts, such as the letter .

For the scope of this challenge, the image that the two-dimensional array Array is an Excel-like table is perfect.Each cell in the table contains a value of int, but you must specify two columns and rows to determine which cell to replace.This time, I only specified "column", but I am getting an error because I am trying to substitute int.

0 12..
0 |   |   |   |
1 |   |   |   |
2 |   |   |   |

2022-09-30 14:23

If you have any answers or tips

© 2023 OneMinuteCode. All rights reserved.