Java中的foreach语句就是for
for(int element:s)
和C#的foreach不同
foreach (int element in s)
public class ScorePrint{
public static void main(String[] args)
{
//foreach 遍历一维数组
double s[]={100,90,80,70,85,90};
for(double element:s)
{
System.out.println(element);
}
//foreach 遍历二维数组
double sc[][]={{100},{90,80},{70,85,90}};
for(double x[]:sc)
{
for(double e:x)
{
System.out.println(e);
}
}
}
}
原博地址
https://blog.csdn.net/weixin_43673589