集册 Java实例教程 将数组作为方法参数传递

将数组作为方法参数传递

欢马劈雪     最近更新时间:2020-01-02 10:19:05

430
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将数组作为方法参数传递

public class Main {

  public static void main(String[] args) {

    int[] num = {7, 8};
    /* 
    *来 自
     N o  w  J a v a . c o m - 时  代  Java
    */


    System.out.println("Before swap");  

    System.out.println("#1: " + num[0]);

    System.out.println("#2: " + num[1]);

    

    // Call the swpa() method passing the num array

    swap(num);  


    System.out.println("After swap");  

    System.out.println("#1: " + num[0]);/*时代Java公众号*/

    System.out.println("#2: " + num[1]);

  }


  // swaps the values if array contains two values.

  public static void swap (int[] source) {

    if (source != null && source
展开阅读全文