One-dimensional array:
int[] a={1,2,3}; for(int i:a){ System.out.print(i+" ");}Output: 1 2 3
Two-dimensional array:
import java.util.Scanner;public class tet {public static void main(String[] args) {//int[][] b={{1,2,3},{4,5,6}};line int[][] a=new int[5][];//The number of rows must be clearly defined for(int i=0;i<5;i++){a[i]=new int[3];//The number of columns is clearly defined}for(int[] i:a){for(int j:i){System.out.print(j+" ");}}}}}Output:
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
The above is the full content of the method of using enhanced for loops in one-dimensional arrays and two-dimensional arrays in Java brought to you by the editor. I hope it will be helpful to everyone and support Wulin.com more~