foreach语句遍历数组
/**
*
* @author hws
* @date 2018-04-11
* foreach语句:
* 创建一个一位数组,并用foreach遍历出来
*/
public class ForeachTest {
public static void main(String[] args) {
int a[]= {1,2,3,4,5};
System.out.println("数组中的元素为:");
//foreach一般用来遍历数组,int x循环变量x,遍历对象a
for(int x:a){
System.out.print(x+" ");
}
}
*
* @author hws
* @date 2018-04-11
* foreach语句:
* 创建一个一位数组,并用foreach遍历出来
*/
public class ForeachTest {
public static void main(String[] args) {
int a[]= {1,2,3,4,5};
System.out.println("数组中的元素为:");
//foreach一般用来遍历数组,int x循环变量x,遍历对象a
for(int x:a){
System.out.print(x+" ");
}
}
}
运行结果图:
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇:没有了
