gpt4 book ai didi

java : get values from matrix

转载 作者:行者123 更新时间:2023-12-02 08:10:18 26 4
gpt4 key购买 nike

每次我对 y 执行操作时,都会从表中获取值 0 和 1。

String[][] columns = {{"col1" , "col2"}};
int[] values = new int[columns.length];
String[] y = { "TEST", "BUG" };

for (int j = 0; j < y.length; j++)
{
//do some actions
//bellow I need to get at the same time col1 and col2
table.getVal(0, columns [0][j])) ?
}

我需要获取 y1 和 y2 上的 col1、col2 的值?我如何使用 getVal 中的列来获得预期值?

谢谢

最佳答案

class MatrixExampleDemo {
public static void main(String[] args) {
int array[][] = { { 1, 3, 5 }, { 2, 4, 6 } };
System.out.println("Row size= " + array.length);
System.out.println("Column size = " + array[1].length);
outputArray(array);
}

public static void outputArray(int[][] array) {
int rowSize = array.length;
int columnSize = array[0].length;

for (int i = 0; i <= 1; i++) {
System.out.print("[");
for (int j = 0; j <= 2; j++) {
System.out.print(" " + array[i][j]);
}
System.out.println(" ]");
}
System.out.println();
}
}

也检查一下............

import java.lang.reflect.Array;
import static java.lang.System.out;

public class CreateMatrix {
public static void main(String... args) {
Object matrix = Array.newInstance(int.class, 2, 2);
Object row0 = Array.get(matrix, 0);
Object row1 = Array.get(matrix, 1);

Array.setInt(row0, 0, 1);
Array.setInt(row0, 1, 2);
Array.setInt(row1, 0, 3);
Array.setInt(row1, 1, 4);

for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
out.format("matrix[%d][%d] = %d%n", i, j, ((int[][])matrix)[i][j]);
}
}

关于java : get values from matrix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7567137/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com