c语言
元素可以通过循环实现在指定位置输入
字符串数组可以通过循环提出每一个字符等
数组之间的元素可以进行运算
int a[100][100] //在数组名字前定义该数组的类型【】这是定义数组的长度,2个是表示二维数组,除了int还可以是char类型--字符类型的数组
#include<string.h>//头文件,可以使用许多的内涵的函数来处理数组如
strlen(str)//获得字符串长度
#include<stdlie>//可以将字符转化大小写等
Java
数组是在内存中存储相同数据类型的连续的空间
数组名代表的是连续空间的首地址
通过首地址可以依次访问数组所有元素
元素在数组中的排序叫做下标从零开始
类型:整型int,字符char,字符串String类型
String s=“this is a string”;
char[ ] c={‘t’,‘h’,‘i’,‘s’,‘i’,‘s’,‘a’,‘c’,‘h’,‘a’,‘r’};
声明一个int类型的数组 ()
int[ ] arr={1,2,3}//数组初始化;
int arr[ ];
arr.length--提取数组的长度
for (int i = 0; i < arr.length; i++) {
循环实现输出计算等基本功能;
Python
matrix=[0,1,2,3]//直接定义
matrix=[[0 for i in range(2)] for i in range(3)]//定义一个二维数组
print(matrix)
>>>[[0, 0], [0, 0], [0, 0]];
matrix=[0 for i in range(4)]//定义一个一维数组
print(matrix)
>>>[0, 0, 0, 0]
### len()//函数:计算列表元素个数
### list(seq)//函数:将元组转换为列表
### max()//函数:返回列表元素的最大值
### min()//函数:返回列表元素的最小值
### index();//从列表中找出某个值第一个匹配项的索引位置
### count()//统计某个元素在列表中出现的次数
list = [1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4]
a = list.count(3)//返回list 中出现3的次数
print(a)
>>>6
### del//根据下标删除元素
list = [1,2,3,4]
del list[3]
print(list)
>>>[1, 2, 3]
### 拼接//使用+
list = [1,2,3,4]
list1 = [5,6,7,8]
list3 = [9,10,11,12]
list2 = list + list1 + list3
print(list2)
>>>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
### 直接改变列表中的元素
list = [1,2,3,4]
list[3]="我是修改之后的元素"
print(list)
#>>> [1, 2, 3, '我是修改之后的元素']
### clear()函数清空列表
b = [1,2,3,4,5,6]
b.clear()
print(b)
>>>[]
c++
//可以定义任何数据类型的数组,以下全部都是有效的数组定义:
float temperature [100] ; // 100 个 float 值的数组
char letter [2 6] ; // 26 个 char 值的数组
double size [1200] ; // 1200 个 double 值的数组
string name [10] ; // 10 个 string 对象的数组
const int SIZE = 6;
int hours [SIZE];
C++ 中的下标编号总是从零开始。
可以实现字符串的逐一输出
#include <iostream>
using namespace std;
int main()
{
const int NUM_EMPLOYEES = 6;
int hours[NUM_EMPLOYEES];
// Input the hours worked by each employee
cout << "Enter the hours worked by " << NUM_EMPLOYEES << " employees: ";
cin >> hours[0];
cin >> hours[1];
cin >> hours[2];
cin >> hours[3];
cin >> hours[4];
cin >> hours[5];
//Display the contents of the array
cout << "The hours you entered are:";
cout << " " << hours[0];
cout << " " << hours[1];
cout << " " << hours[2];
cout << " " << hours[3];
cout << " " << hours[4];
cout << " " << hours[5] << endl;
return 0;
}
C++ 不执行数组边界检查。这意味着程序员编写的程序,可能会意外地允许一个数组的下标越界。这也是为什么程序8-3的第23行要测试循环控制变量值的原因,必须确保它小于 NUM_EMPLOYEES(它是数组的大小),然后才允许循环继续迭代和读取值。
c#
//int变量的二维数组
int [,] names;
int [ , , ] names;//int 变量的三维数组
//Console.WriteLine("=> Rectangular Multidmensional array.");
// 矩形多维数组
int[,] myMatrix;
myMatrix = new int[6, 6];
// 填充6*6数组
for (int i = 0; i < 6; i++)
for (int j = 0; j < 6; j++)
myMatrix[i, j] = i * j;
// 输出6*6数组
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 6; j++)
Console.Write(myMatrix[i, j] + "\t");
Console.WriteLine();
}