package com.fqs.demo; public class ChongZ { //遍历数组以[第一个值,第二个值,....最后一个值]的格式 public static void main(String[] args) { int[ ]array= {12,13,14,8,9,0,6};//给数组赋值 getArray(array); } public static void getArray(int [] array) {//形参是数组形式 for(int index=0;index<array.length;index++) { if(index==0) { System.out.print("["); } if(index<array.length-1) { System.out.print(array[index]+","); } if(index==array.length-1) { System.out.print(array[index]+"]"); } } } }
标签:遍历,int,....,数组,格式,array,public From: https://www.cnblogs.com/haha1988/p/17053438.html