二维数组 (multiplication/division)

Two dimensional array (multiplication/division)

我目前创建了一个名为 Array Math 的 class,它将按位置相乘加载到 10x10 数组中,如代码下方显示的图像所示,但是我想要做的是将每个位置除以2 乘法后。所以换句话说,目前我只是将这些数字加载到数组中(行 * 列)/ 2。我不确定如何从逻辑上解决这个问题,因为我使用两个 for 循环来产生行和列之间的乘法。

class ArrayMath
{
        private static final int tableSize = 10;
        public static void main(String[] args)
        {
                int table[][] = new int [tableSize][tableSize];
                for (int row = 1; row <= 10; row++)
                {
                        for (int col = 1; col <= 10; col++)
                        {
                                System.out.printf(row * col +"\t");
                        }
                        System.out.println();
                }
        }
}

Output of array

您只需添加 /2.0。操作顺序负责其余部分

System.out.printf( ( row * col / 2.0 ) + "\t" );

您需要使用 2.0 的原因是,否则 Java 会舍入结果。