我們如何在 Java 方法中按值傳遞引數?


按值傳遞引數是指用一個引數呼叫方法。透過這種方式,引數值傳遞給引數。

示例

public class SwappingExample {
   public static void swapFunction(int a, int b) {
      int c = a+b;
      System.out.println("Sum of the given numbers is ::"+c);
   }

   public static void main(String[] args) {
      int a = 30;
      int b = 45;
      swapFunction(a, b);
   }
}

輸出

Sum of the given numbers is ::75

更新時間:30-Jul-2019

208 次瀏覽

開啟您的職業生涯

完成課程,獲得認證

開始學習
廣告
© . All rights reserved.