java二维数组foreach语句问题 for(int x:a) {if(x==a.length) //不是很明白

发布网友 发布时间:2022-04-23 18:11

我来回答

3个回答

热心网友 时间:2023-10-12 10:04

foreach代表高级for循环,是for循环的简化写法,可以遍历集合、数组

我把foreach分解代码给你写在下面吧

public class Tautog {
  public static void main(String args[]){
int[][]arr={{3,5},{1,2,6},{5,8,9}};
for(int i = 0;i<arr.length;i++){
for(int j = 0;j<arr[i].length;j++){
    int x = arr[i][j];
    if(x==arr[i].length){
    System.out.print(x);
    }
    else{
    }
            System.out.print(x+" ");
      }
  }
  }
}

热心网友 时间:2023-10-12 10:05

如果数组中元素的值等于该数组的长度。

热心网友 时间:2023-10-12 10:05

for(int x:a)
增强for循环 x为a的一个元素

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com