如何检查2D数组是否包含值

时间:2019-01-19 12:32:02

标签: java arrays matrix input adjacency-matrix

我有一些原始数据,据此我创建了一个带有整数的2D数组。现在我想建立一个邻接矩阵。

因此,我想检查一下,如果我的2D数组包含例如值3和2。如果是,则我的另一个数组应获取值1,否则值为0。

但是我很困惑,如何检查2D阵列。

public class FileInput{
try {
        Scanner input = new Scanner(new File("Raw"));
        int m = 2772;
        int n = 1;
        int[][] inputarray = new int[m][n];

        while (input.hasNextLine()) {
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                   try{//    System.out.println("number is ");
                    inputarray[i][j] = input.nextInt();
                     // System.out.println("number is "+ a[i][j]);
                    }
                   catch (java.util.NoSuchElementException e) {
                       // e.printStackTrace();}
                    }
                }
            }         
       }

      private boolean adjMatrix[][];
          private int numVertices;

          public Graph(int numVertices) {
              this.numVertices = numVertices;
              adjMatrix = new boolean[numVertices][numVertices];
        }

          public void addEdge(int i, int j) {
              for (int row=0; row<numVertices; row++) {
              for (int col=0; col<numVertices; col++)
              if (inputarray.contains = true)
              {
                  adjMatrix [i][j]= true;
              }
              else
                  adjMatrix [i][j] = false;

        }
....

0 个答案:

没有答案