1. 程式人生 > >雲課堂數組1

雲課堂數組1

[] nbsp can put n) ner int() 聲明 分配

1.聲明數組:

據類型 數組名[]

據類型[] 數組名(一般用這種)

int[] a;

2.分配空間:

數據類型[] 數組名 = new 數據類型[大小];

a=new int[5]

3.賦值

方法一:邊聲邊賦值

int [] score ={89,79,76};

int[] score =new int[]{89,79,76};

a[8]=8;

方法二:動態地從鍵盤錄入信息並賦值

Scanner input = new Scanner(System.in);

for(int i=0; i<30;i++){

score[i] = input.nextInt();

}

4.處理數據

五個數的平均值

avg=(score[0]+score[1]+score[2]+score[3]+score[4]) /5

乘法運算

a[0]=a[0]*10;

雲課堂數組1