JavaSE系列代码04:以数组为参数的方法调用

An array is an ordered sequence of elements. If you name a collection of a limited number of variables of the same type, the name is an array name. The variables that make up an array are called the components of the array, also called the elements of the array, and sometimes called subscript variables. The number used to distinguish the elements of an array is called a subscript. Array is a kind of form in which several elements of the same type are organized in an orderly form for the convenience of processing in programming. The collection of these ordered data elements of the same kind is called an array.

public class Javase_04      //定义主类
{
  public static void main(String[] args)
  {
    int[] a={8,3,7,88,9,23};  //定义一维数组a
    LeastNumb MinNumber=new LeastNumb ();
    MinNumber.least(a);   //将一维数组a传入least()方法
  }
}
class LeastNumb    //定义另一个类
{
  public void least(int[] array)  //参数array接收一维整型数组
  {
    int temp=array[0];
    for (int i=1;i<array.length;i++)
      if (temp>array[i])
        temp=array[i];
    System.out.println("最小的数为:"+temp);
  }
}
发布了13 篇原创文章 · 获赞 160 · 访问量 8545

猜你喜欢

转载自blog.csdn.net/blog_programb/article/details/105376652