⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testpassbyvalue.java

📁 此源码为机械工业出版社出版的《Java语言程序设计》第三版所配套的书中所有源代码。
💻 JAVA
字号:
// TestPassByValue.java: Demonstrate passing values to methods
public class TestPassByValue
{
  // Main method
  public static void main(String[] args)
  {
    // Declare and initialize variables
    int num1 = 1;
    int num2 = 2;

    System.out.println("Before invoking the swap method, num1 is " +
      num1 + " and num2 is " + num2);

    // Invoke the swap method to attempt to swap two variables
    swap(num1, num2);

    System.out.println("After  invoking the swap method, num1 is " +
      num1 + " and num2 is " + num2);
  }

  // The method for swapping two variables
  static void swap(int n1, int n2)
  {
    System.out.println("    Inside the swap method");
    System.out.println("    Before swapping n1 is " + n1
      + " n2 is " + n2);

    // Swapping n1 with n2
    int temp = n1;
    n1 = n2;
    n2 = temp;

    System.out.println("    After  swapping n1 is " + n1
      + " n2 is " + n2);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -