1,找出数组中最大的元素:
Double max = a[0]
For (int i = 1; I < a.length; i++) {
If (a[i] > max ) max = a[i]
}
2,计算数组元素的平均值
Int N = a.length
Double sum = 0.0
For (int i = 0; I < N; ) {
Sum + = a[i]
}
Double average = sum/N
3, 复制数组
Int N = a.length
Double[] b = new double [N]
For (int I = 0; i< N; i++) {
b[ i ] = a [ i ]
}
4, 调到数组元素的顺序
Int N = a.length
For (int I = 0; I < N/2; i++ ) {
Double temp = a[ i ]
A[ i ] = a [ N-1-i ]
a [ N-1-i ] = temp
}
5, 矩阵相乘(方阵)
a[ ][ ] * b[ ][ ] = c[ ][ ]
// I 代表 矩阵 a 的行 ,j 代表 矩阵 b 的列, k 代表他们数字相同的行和列
int N = a.length
double[ ][ ] c = new double[N],N]
for (int I = 0; I < N; j ++) {
for( int j = 0; j < N; j ++ ){
// 计算行 I 和列 j 的点乘
for( int K = 0 ;K < N; K++ ){
c[ I ][ j ] + = a[ I ][ k ] * b[ K ][ j ]
}
}
网友评论