增强for循环就是循环的更简便方法,看代码
public class 增前for {
public static void main(String[] args) {
// TODO Auto-generated method stub
int v [] = new int []{5,6,9,7,8,54};
//for (int i=0;i<v.length;i++){
//int e = v[i];
//System.out.println(e);
//}
int max=-1;
for(int e:v){
if(e>max){
max=e;
}
}
System.out.println(max);
}
}
增强for循环就是e:v把v数组里的值代入e中,不用写一个长长的for循环,除了数组之外同样还有许多用处,可以提高简化代码并提高可读性