求JAVA高手过目

public class Repetition {
public static void main(String[] args) {
int arr[]={7,10,1};
System.out.println("一位数组中的元素分别为:");
for(int x;arr){
System.out.println(x);
}
}

}
冒号也报错呀

我晕,你看报错了没?
"for each" statements are only available if source level is 5.0
说明你的 Jdk 版本低于 5.0,不支持这个特性。

只能改成普通的 for 语句:

for (int i=0; i<arr.length; i++)
System.out.println(arr[i]);
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-06-23
好啦。现在程序已经帮你修改好了。你看看
public class Repetition
{
public static void main(String[] args)
{
int[] arr={7,10,1};
System.out.println("一位数组中的元素分别为:");
for(int x=0;x<arr.length; x++)
{
System.out.println(arr[x]);
}
}
}
在这个程序里面你的那个那个FOR循环是有问题的。是需要获取它的每一个索引号的。这样就会可以实现你要的功能了。。
第2个回答  2010-06-23
for 里面是 冒号“:” ,不是分号“;”

看看别人的例子:
public class TestForInterator {
public static void main (String args[]){
int[] intArray = {1, 2, 3, 4};//创建一个数组

for(int i : intArray){//循环取出数组里的每个数赋值给i,每取一次执行一遍{}中代码

System.out.print(i +" ");//打印数组里的数
}
}
}
第3个回答  2010-06-23
for (int x : arr)
代码里面要是:冒号
嘿嘿
第4个回答  2010-06-23
for(int x:arr){
相似回答