时间:2016.11.28
>>>>>>>>>>>>>>>>>>>>
一维数组:
静态:声明数组,并赋值。
举例: int[] i={1,2,3,4,5};
动态:只定义范围,不赋值,(int默认值为0)
举例:int[] i=new int[2];
二维数组:
静态:
举例: double [][] a={
{1.1,1.2},
{2.1,2.2}
};动态:
举例:String str[][]=new String[2][];
String st[]={"strty","tr1","str2"};
String st1[]={"sr","sB","AA"};
str[0]=st;
str[1]=st1;
代码实例:
1 package lianxi; 2 //求数组st长度小于3,并且包含s,的字符串相加。 3 public class shuzu { 4 public static void main(String[] args) { 5 String sum = ""; 6 String s; 7 String str[][]=new String[2][]; 8 9 String st[]={"strty","tr1","str2"}; 10 String st1[]={"sr","sB","AA"}; 11 12 13 str[0]=st; 14 str[1]=st1; 15 16 for(int i=0;i<str.length;i++){//控制外层数组 17 for(int j=0;j<str[i].length;j++){//控制内层数组 18 if(str[i][j].contains("s")&&str[i][j].length()<=3){ 19 sum=sum+str[i][j];} 20 } 21 } 22 System.out.println(sum); 23 } 24 }