数组操作中,在栈内存中保存的永远时数组的名称,只开辟了栈内存空间的数组是永远无法使用的,必须有指向的堆内存才可以使用,要想开辟新的对内存则必须使用new关键字,然后只是将此堆内存的使用权交给了对应的栈内存空间,而且一个堆内存空间可以同事被多个栈内存空间指向,即一个人可以有多个名字,人就相当于堆内存,名字就相当于栈内存
int score[] = null; //声明数组,数组是引用类型,默认值是null
score = new int[3]; //位数组开辟堆内存空间,大小位3
public class ArrayDemo
{
public static void main(String args[])
{
int score[] = {67,89,87,69,90,100,75,90} ; //声明数组
for (int i=1;i<score.length;i++){
for (int j=0;j<score.length;j++){
if (score[i] < score[j])
{
int temp = score[i];
score[i] = score[j];
score[j] = temp;
}
}
}
for(int i=0;i<score.length;i++) //数组输出
{
System.out.println(score[i] + "\t");
}
}
}