# 一维数组与二维数组的声明与定义

/**
*
*/
package test20111005;
/**
* @author FlyingFire
* @date:2011-11-18 上午04:33:36
* @author ：代码整理
* @introduce :一维数组与二维数组的初始化
*summary：
*/
public class ArrayTest {

public static  void main(String args[]){
//一维数组
String  strArray[];//仅是声明
String  strArray1[]=new String[5];//一维数组的定义，指定了数组长度，未赋初始值
String  strArray2[]={"我","心","飞","翔"};//一维数组的定义，指定了数组长度(4)，并赋初始值
String  strArray3[]=new String[]{"我","心","飞","翔"};//一维数组的定义，指定了数组长度(4)，并赋初始值
/*
* String  strArray4[];
*    strArray4=new String{"我","心","飞","翔"};
*    错误：数组常量只能在数组初始化的时候使用
*/
//二维数组
String strArray5[][]=new String[3][1];//二维数组的定义，指定行列，未赋初始值
String strArray6[][]={{"自","古","逢","秋","悲","寂","寥"},
{"我","言","秋","日","胜","春","朝"},
{"晴","空","一","鹤","白","云","上"},
{"便","引","诗","情","到","碧","霄"}};//二维数组的定义，指定行列，赋初始值
String strArray7[][]={ {"哈","哈","哈"},
{"哈","哈"},
{"哈","哈","哈","哈","哈"},
{"哈"}};//数组空间并非连续分配，所以不必每一维空间相同
}

}

• 0

开心

• 0

板砖

• 0

感动

• 0

有用

• 0

疑问

• 0

难过

• 0

无聊

• 0

震惊

#include <stdio.h> /* 在gcc */ int main(void) { int a[3][4] = {{1, 2, 3}, {4, 5, 6}, {7
1.声明 类型说明符 数组名[][] / [][]数组名； example：int a[][]; 2.初始化 数组名=new 类型说明
#include <iostream> #include <time.h> using namespace std; void setdata(int a[8][
#include <iostream> using namespace std; int main() { int i,j,t; int a[5][4]={{0,1},{4,
/* * 程序的版权和版本声明部分 * Copyright (c)2012, 烟台大学计算机学院 * All rightsreserved. *