首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Java 数组步骤

2012-10-16 
Java 数组方法public class test {public static void main(String[] args) {// TODO Auto-generated meth

Java 数组方法

public class test {public static void main(String[] args) {// TODO Auto-generated method stubint[] a = {11,1,5,3,32,23};Arrays.sort(a);for(int i : a){System.out.println(i);}String str = Arrays.toString(a);System.out.printf("%s",str);int[] b = Arrays.copyOfRange(a, 3,4);for(int i : b){System.out.printf("%d", i);}int index = Arrays.binarySearch(a, 3,4,32);System.out.printf("%s", index);int[] c = new int[5];Arrays.fill(c,4);System.out.println(Arrays.toString(c));//---java.lang.Systemint[] from = {1,2,53,4,25,16,27,18,9};int[] to = {1,22,53,4,25,16,2,8,9};System.arraycopy(from, 0, to, 1, 1);System.out.println(Arrays.toString(to));//--float[][] f = {{1,2,4},{3,1,2},{2,7,5}};System.out.println(Arrays.deepToString(f));for(float[] row : f )for(float col : row)System.out.println(col);//---不规则数组int[][] oods = new int[5][];for(int i=0;i<5;i++){oods[i] = new int[i+1];}for(int[] row : oods){for(int col : row){System.out.print(col+"\t");}System.out.println();}}

热点排行