package test01;
import java.util.Arrays;
/**
* 打印数组的几种方法
* @author Administrator
*
*/
public class PrintArrayTest {
public static void main(String args[]) {
int[] b= {5,7,2,9,4,1,0,5,7};//新建数组
int[] arr=new int[] {5,7,2,9,4,1,0,5,7};//新建数组
//1
System.out.println(Arrays.toString(arr));//[5, 7, 2, 9, 4, 1, 0, 5, 7]
//2
for(int n: arr)
System.out.print(n+", ");//5, 7, 2, 9, 4, 1, 0, 5, 7,
//3
System.out.print('\n');
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + ", ");//5, 7, 2, 9, 4, 1, 0, 5, 7,
}
//4
System.out.print('\n');
System.out.println(Arrays.asList(arr));//[[I@136432db]
}
}
数组的打印方式(java)
最新推荐文章于 2024-05-28 09:27:06 发布