英文:
Compare values in 2D array. Every value to first row
问题
数据结构:
我想要将从第2行开始的每个值与第1行中的每个值进行比较,以及与结束后的每个值进行比较。在这个示例中,我想要将每个红色-ish值与绿色、黄色和紫色的值进行比较。数据结构可以有更多的列和行,但是从第2行开始的所有值都始终与第一行的值进行比较。
示例:
我想要将所有的值与[75.06176,39.44008]
,[36.08646,26.384703]
以及[14.038518,55.827003]
进行比较。
行数或列数不是固定的。
有任何想法如何做到这一点吗?
英文:
Data structure:
I would like to compare every value from 2. row onward to the end, to each value in 1.row. In this example I would like to compare every red-ish value to green, yellow and purple value. The data structure can have more columns and rows, but all values from 2.row onwards are always comparing to the values of firs row.
Example:
I would like to compare all the values to [75.06176,39.44008]
, [36.08646,26.384703]
and [14.038518,55.827003]
.
Number of rows or columns is not fixed.
Any ideas how to do it?
答案1
得分: 1
根据我的理解,您想要将一行的值与另一行进行比较。为此,您需要使用两个for循环来遍历二维数组。
for (int i = 0; i < N; i++) {
for (int j = 0; j < c; j++) {
if (arr[i][j] >= 0)
System.out.println("您想要打印的任何内容");
}
}
如果我误解了您的问题,请您原谅。
英文:
As per my understanding, You want to compare values of one row with another. For that You need 2 for loops for 2D Array.
for(int i=0; i<N; i++){
for (int j=0; j<c; j++) {
if (arr[i][j]>=0)
System.out.println("Anything you want to print");
}
}
Please excuse me if I misunderstood your question.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论