public class Tautog { // 创建类
public static void main(String[] args) { // 主方法
int arr1[][] = { { 4, 3 }, { 2, 1} }; // 定义二维数组
System.out.println("数组中的元素是:"); // 提示信息
for (int x[] : arr1) { // 外层循环变量为一维数组
for (int e : x) { // 循环遍历每一个数组元素
if (e == x.length) { // 判断变量是二维数组中的最后一个元素
System.out.print(e); // 输出二维数组的最后一个元素
} else
// 如果不是二维数组中的最后一个元素
System.out.print(e + "、"); // 输出信息
}
}
}
}
public static void main(String[] args) { // 主方法
int arr1[][] = { { 4, 3 }, { 2, 1} }; // 定义二维数组
System.out.println("数组中的元素是:"); // 提示信息
for (int x[] : arr1) { // 外层循环变量为一维数组
for (int e : x) { // 循环遍历每一个数组元素
if (e == x.length) { // 判断变量是二维数组中的最后一个元素
System.out.print(e); // 输出二维数组的最后一个元素
} else
// 如果不是二维数组中的最后一个元素
System.out.print(e + "、"); // 输出信息
}
}
}
}
解决方案 »
- RCP开发状态栏设置的问题
- 1,2,4,8,32....,有这么一组数。请求出第32位数值是多少?
- 怎样在同一个JFrame里面显示不同panel的内容?
- 连接sql2005老显示找不到合适驱动,求助!!
- 怎么把一个文件转换成byte〔〕型
- 为什么我用这段HTML语言无法显示Applet控件?
- Error: Class jni could not be found.原因是什么?谢谢!
- 这个程序的compareTo应该怎能样写才能得出正确结果?
- 请教:如何将JTable里的内容显示在tool tip中?
- 100以内素数和问题
- 利用Properties创建配置文件遇到疑问
- ACM奇怪问题------杭电oj 1009水题奇葩问题----浮点输出问题
System.out.print(e);
}
for (int i=0;i<x.length,i++)
if (i == x.length-1)//输出x[i]
System.out.print(e); // 输出二维数组的最后一个元素
}
这里的e并不是你想象中一维数组的下标,而是一维数组元素的值