java : get values from matrix

匿名 (未验证) 提交于 2019-12-03 01:40:02

问题:

for each time I do an action on y , get values 0 and 1 from table.

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])) ?     } 

I need to get value of col1, col2 on y1 and on y2 ? how could I use columns in the getVal to have the expected values ?

thanks,

回答1:

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();     } } 

Check this also...................

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]);     } } 


回答2:

I don't quite see the logic in your code, but general matrix operations would be:

String[][] matrix = new String[10][10]; matrix[0][0] = "1.1"; matrix[0][1] = "1.2"; matrix[1][0] = "2.1"; matrix[2][1] = "2.2";  int x = 0; // col int y = 1; // row String val = matrix[y][x]; // 1.2 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!