作业帮 > 综合 > 作业

6.Write a procedure that receives a two dimensional array th

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/21 16:54:45
6.Write a procedure that receives a two dimensional array that has been filled with integers.Use
请解释每步的意思
Write a procedure that receives a two dimensional array that has been filled with integers.Use two “for loops” to search through the array to find any value greater than 7.When a value is found that is greater than 7 then the value and its location within the array must be printed to the screen.(“Value found was “7” at [1][3]”).
public class Finder {

public static void find(int[][] d){
for(int i = 0;i < d.length; i++){
for(int j = 0;j < d.length;j++){
if(d[i][j] > 7){
String s = "Value found was 7 at "
+ "[" + i + "]" + "[" + j + "]";
System.out.println(s);
}
}
}
}

public static void main(String[] args) {
int[][] test = {
{
7,8,9,10,11
},
{
7,8,9,10,11
},
{
7,8,9,10,11
},
{
7,8,9,10,11
},
{
7,8,9,10,11
},
};
Finder.find(test);
}
}
再问: 能标注下每步的意思么
再答: for(int i = 0;i < d.length; i++){ //for{}for{}遍历数组 for(int j = 0;j < d.length;j++){ if(d[i][j] > 7){ //找到大于7的数 String s = "Value found was 7 at " + "[" + i + "]" + "[" + j + "]";//打印出找到的这个数的i,j System.out.println(s); } } } 这个代码很简单了,基本不需要解释,除非你没好好看书