数组的打印(3种)及简单调用
2021-02-02 07:15
标签:foreach array test === arrays col each 调用 system 数组的定义及打印 调用数组 数组的打印(3种)及简单调用 标签:foreach array test === arrays col each 调用 system 原文地址:https://www.cnblogs.com/Leafbud/p/12811063.html 1 import java.util.Arrays;
2
3 public class test7 {
4
5 /**
6 *
7 * @param args
8 */
9 public static void main(String[] args) {
10 int[] array1 = {1,2,3};
11 int[] array2 = new int[3];//定义array2的长度
12 int[] array3 = new int[]{1,2,3,4};
13 //数组遍历
14 for (int i = 0; i ) {
15
16 System.out.print(array1[i]);
17 }
18 System.out.println();
19 System.out.println("=======foreach=======");
20 for (int i:array3) {//i为值,array是数组
21 System.out.print(i);
22 }
23 System.out.println();
24 System.out.println("=====数组内容以字符串的形式输出=====");
25 System.out.println(Arrays.toString(array1));
26 }
27 }
1 public class test7 {
2
3 /**
4 *
5 * @param arr
6 *
7 */
8 public static void fac(int[] arr) {
9 for (int i = 0; i ) {
10 System.out.print(arr[i] + " ");
11 }
12 }
13 public static void main(String[] args) {
14 int[] arr = {1,2,3};
15 fac(arr);
16 }
17 }