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);
			}
		}
	}
}

 

posted on 2020-11-02 00:08  海月CSDN  阅读(940)  评论(0编辑  收藏  举报