• Java学习(六)


    public class MatrixAddition{
        public static void main(String args[]){
            int i,j,k;
            int a[][] = new int [3][4];
            int b[][] = {{1,5,2,8},{5,9,10,-3},{2,7,-5,-18}};
            int c[][] = new int[3][4];
            for(i = 0;i < 3;i++)
                for(j = 0;j < 4;j++)
                    a[i][j] = (i + 1)*(j + 2);
            for(i = 0;i < a.length;i++)
                for(j = 0;j < a[i].length;j++)
                    c[i][j]=a[i][j]+b[i][j];
        System.out.println("*******Matrix C********");
            for(i = 0;i < c.length;i++){
                for(j = 0;j < c[i].length;j++)
                    System.out.print(c[i][j]+" ");
                    System.out.print("
    ");
            }
        }
    }

    ·数组的各种运用

    public class ArrayDemo{
        static float AverageArray(float a[]){
            float average = 0;
            int i;
            for(i =0;i < a.length;i++){
                average = average + a[i];
            }
            return average/a.length;
        }
        public static void main(String[] args){
            float average,a[] = {1,2,3,4,5};
            average = AverageArray(a);
            System.out.println("average = "+average);
        }
    }

    ·数组作为方法的参数。

    ·形参列表中,数组名后的括号不能省略,可以不给出数组元素的个数;实参列表中,数组名后面不需要括号。

    ·数组名作为实参时,传递的是地址,即实参和形参具有相同的存储单元。

  • 相关阅读:
    [hihocoder1509][异或排序]
    [hdu6148][Valley Numer]
    [hdu2089][不要62]
    [luoguU42591][小T的绝对值]
    [luogu2073][送花]
    [bzoj4709][柠檬]
    [luogu2114][起床困难综合症]
    [codevs3342][绿色通道]
    [luoguU42591][小T的面试题]
    [noip][2014]
  • 原文地址:https://www.cnblogs.com/sheril/p/5557871.html
Copyright © 2020-2023  润新知