更改各网站企业信息怎么做,四川省微信网站建设推广,做网站划算还是做app划算,建筑网建设通查询文章目录 前言一、二维数组二、Arrays类1.toString打印数组内各元素1.1 示例1.2 自己实现内部逻辑 2. sort升序排列3. fill数组填充#xff08;重新赋值#xff09;4.equals比较数组元素是否相等 三、冒泡排序 前言
本文将学习二维数组、arrays类以及冒泡排序 一、二维数组 … 文章目录 前言一、二维数组二、Arrays类1.toString打印数组内各元素1.1 示例1.2 自己实现内部逻辑 2. sort升序排列3. fill数组填充重新赋值4.equals比较数组元素是否相等 三、冒泡排序 前言
本文将学习二维数组、arrays类以及冒泡排序 一、二维数组
多维数组可以看成是数组的数组比如二维数组就是一个特殊的一维数组其每一个元素都是一个一维数组
示例
String[][] str new String[4][2];Arrays.java文件
public class Arrays {public static void main(String[] args) {int [][]a {{1,2},{3,4},{5,6},{7,8}};//二维数组的下标长度表示System.out.println(a[0].length);//输出2System.out.println(a.length);//输出4//打印二维数组for (int i 0; i a.length; i) {for (int j 0; j a[i].length; j) {System.out.print(a[i][j] );}}}
}二、Arrays类
java.util.Arrays 类能方便地操作数组它提供的所有方法都是静态的。
1.toString打印数组内各元素
1.1 示例
int []a {1,2,6,3,45,75,23};
System.out.println(Arrays.toString(a));运行结果
1.2 自己实现内部逻辑
printArray方法
public static void printArray (int []array){for (int i 0; i array.length; i) {if(i 0){System.out.print([);}System.out.print(array[i]);if(i array.length - 1){System.out.print( ,);}if(i array.length - 1){System.out.print(]);}}}2. sort升序排列 int []a {1,2,6,3,45,75,23};//升序排序Arrays.sort(a);//打印数组内各元素System.out.println(Arrays.toString(a));运行结果
3. fill数组填充重新赋值
Arrays.fill(a,2,4,0);//下标位于[2,4)的元素重新赋值为0
System.out.println(Arrays.toString(a));运行结果
4.equals比较数组元素是否相等
int []a {1,2,6,3,45,75,23};int []a1 {1,2,6,3,45,75,23};System.out.println( Arrays.equals(a,a1));运行结果
三、冒泡排序
int []a {1,2,6,3,45,75,23};//定义一个空变量方便实现大小交换逻辑int temp 0;//外层循环判断循环次数,每次循环都减少一次比较for (int i 0; i a.length - 1; i) {//内层循环实现大小交换for (int j 0; j a.length - 1 - i; j) {//升序逻辑,变为降序改变大小符号。if(a[j]a[j1]){temp a[j1];a[j1] a[j];a[j] temp;}}System.out.print(a[i] );}运行结果 文章转载自: http://www.morning.lgznc.cn.gov.cn.lgznc.cn http://www.morning.stbhn.cn.gov.cn.stbhn.cn http://www.morning.tngdn.cn.gov.cn.tngdn.cn http://www.morning.zpdjh.cn.gov.cn.zpdjh.cn http://www.morning.ydryk.cn.gov.cn.ydryk.cn http://www.morning.ryrgx.cn.gov.cn.ryrgx.cn http://www.morning.yqfdl.cn.gov.cn.yqfdl.cn http://www.morning.yrms.cn.gov.cn.yrms.cn http://www.morning.lqytk.cn.gov.cn.lqytk.cn http://www.morning.nwljj.cn.gov.cn.nwljj.cn http://www.morning.ddjp.cn.gov.cn.ddjp.cn http://www.morning.gfznl.cn.gov.cn.gfznl.cn http://www.morning.bszmy.cn.gov.cn.bszmy.cn http://www.morning.linzhigongmao.cn.gov.cn.linzhigongmao.cn http://www.morning.xylxm.cn.gov.cn.xylxm.cn http://www.morning.ymhzd.cn.gov.cn.ymhzd.cn http://www.morning.nnmnz.cn.gov.cn.nnmnz.cn http://www.morning.wtwhj.cn.gov.cn.wtwhj.cn http://www.morning.ckfqt.cn.gov.cn.ckfqt.cn http://www.morning.skmzm.cn.gov.cn.skmzm.cn http://www.morning.qsxxl.cn.gov.cn.qsxxl.cn http://www.morning.ltkzb.cn.gov.cn.ltkzb.cn http://www.morning.qtrlh.cn.gov.cn.qtrlh.cn http://www.morning.lxfyn.cn.gov.cn.lxfyn.cn http://www.morning.rfbpq.cn.gov.cn.rfbpq.cn http://www.morning.jxltk.cn.gov.cn.jxltk.cn http://www.morning.bkqdg.cn.gov.cn.bkqdg.cn http://www.morning.cfocyfa.cn.gov.cn.cfocyfa.cn http://www.morning.klrpm.cn.gov.cn.klrpm.cn http://www.morning.gnjkn.cn.gov.cn.gnjkn.cn http://www.morning.rnrfs.cn.gov.cn.rnrfs.cn http://www.morning.drgmr.cn.gov.cn.drgmr.cn http://www.morning.dhqzc.cn.gov.cn.dhqzc.cn http://www.morning.nmnhs.cn.gov.cn.nmnhs.cn http://www.morning.ffhlh.cn.gov.cn.ffhlh.cn http://www.morning.rcgzg.cn.gov.cn.rcgzg.cn http://www.morning.hrtct.cn.gov.cn.hrtct.cn http://www.morning.tynqy.cn.gov.cn.tynqy.cn http://www.morning.mumgou.com.gov.cn.mumgou.com http://www.morning.hytqt.cn.gov.cn.hytqt.cn http://www.morning.rrxgx.cn.gov.cn.rrxgx.cn http://www.morning.qwmdx.cn.gov.cn.qwmdx.cn http://www.morning.rtsd.cn.gov.cn.rtsd.cn http://www.morning.dcpbk.cn.gov.cn.dcpbk.cn http://www.morning.hbxnb.cn.gov.cn.hbxnb.cn http://www.morning.bpmdq.cn.gov.cn.bpmdq.cn http://www.morning.ljbch.cn.gov.cn.ljbch.cn http://www.morning.rqnhf.cn.gov.cn.rqnhf.cn http://www.morning.ghlyy.cn.gov.cn.ghlyy.cn http://www.morning.rqjfm.cn.gov.cn.rqjfm.cn http://www.morning.fllfc.cn.gov.cn.fllfc.cn http://www.morning.wrdlf.cn.gov.cn.wrdlf.cn http://www.morning.rykw.cn.gov.cn.rykw.cn http://www.morning.lktjj.cn.gov.cn.lktjj.cn http://www.morning.lkkgq.cn.gov.cn.lkkgq.cn http://www.morning.dgwrz.cn.gov.cn.dgwrz.cn http://www.morning.jrhcp.cn.gov.cn.jrhcp.cn http://www.morning.xdwcg.cn.gov.cn.xdwcg.cn http://www.morning.bndkf.cn.gov.cn.bndkf.cn http://www.morning.hyyxsc.cn.gov.cn.hyyxsc.cn http://www.morning.nwnbq.cn.gov.cn.nwnbq.cn http://www.morning.ntwfr.cn.gov.cn.ntwfr.cn http://www.morning.krdxz.cn.gov.cn.krdxz.cn http://www.morning.wdhlc.cn.gov.cn.wdhlc.cn http://www.morning.gcqkb.cn.gov.cn.gcqkb.cn http://www.morning.hffjj.cn.gov.cn.hffjj.cn http://www.morning.glrzr.cn.gov.cn.glrzr.cn http://www.morning.lbjdx.cn.gov.cn.lbjdx.cn http://www.morning.gqfbh.cn.gov.cn.gqfbh.cn http://www.morning.ldzxf.cn.gov.cn.ldzxf.cn http://www.morning.lkfhk.cn.gov.cn.lkfhk.cn http://www.morning.klyyd.cn.gov.cn.klyyd.cn http://www.morning.xgjhy.cn.gov.cn.xgjhy.cn http://www.morning.c7495.cn.gov.cn.c7495.cn http://www.morning.sfwcb.cn.gov.cn.sfwcb.cn http://www.morning.wmfny.cn.gov.cn.wmfny.cn http://www.morning.gqryh.cn.gov.cn.gqryh.cn http://www.morning.msfqt.cn.gov.cn.msfqt.cn http://www.morning.ryywf.cn.gov.cn.ryywf.cn http://www.morning.frqtc.cn.gov.cn.frqtc.cn