Java for loop usage
In Java, the for loop is written in another way: foreach (generally used to traverse the entire array without worrying about cross-border issues ).
1.1) General statement:
package foreach.main.sn;public class Foreach {public static void main(String[] args) {int[] arr = {1,2,3,4,5};for (int i = 0; i < arr.length; ++i){System.out.println(arr[i]);}}}
1.2) foreach writing: (note the following:
TIs a temporary variable value used to save the value of the array currently traversed. If you need to change the value of the array, you cannot use this method to traverse)
package foreach.main.sn;public class Foreach {public static void main(String[] args) {int[] arr = {1,2,3,4,5};for (int t : arr){System.out.println(t);}}}
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KMqOpyrnTw2ZvcmVhY2ix6cD6tv7OrMr91 + mjugo8cD48cHJlIGNsYXNzPQ = "brush: java;"> package foreach. main. sn; public class Foreach {public static void main (String [] args) {int [] [] arr2 = {1, 2, 3}, {4, 5}, {6, 7, 8 }}; for (int t1 []: arr2) {for (int t2: t1) {System. out. print (t2);} System. out. println ();}}}
Address: http://blog.csdn.net/qingdujun/article/details/40799561